Showing posts with label launcher. Show all posts
Showing posts with label launcher. Show all posts

Monday, March 31, 2014

Android Tip - Hide App Icon in Launcher

You may have an application that contains a broadcast receiver and for some reasons you want to hide the application icon in the Launcher after it has been installed (so that the user doesn’t know the app existed).

Programmatically Hiding the Icon


If you want the application icon to be visible after installation and hide it programmatically afterwards, you can use the following code snippets:

    PackageManager p = getPackageManager();
    p.setComponentEnabledSetting(getComponentName(),
        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP);
   
When the above statements are executed, the application icon in the Launcher will disappear after a while.

Declaratively Hiding the Icon

The easist way to hide your application icon from the Launcher is to remove the android.intent.category.LAUNCHER category from your app’s AndroidManifest.xml file. However, simply doing so will also render your broadcast receiver useless – it won’t respond to your broadcasts.

To fix this, you need to also add in the android.intent.category.DEFAULT category, like this:

        <activity
            android:name=
            "net.learn2develop.locationmonitor.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name=
                    "android.intent.action.MAIN" />                              
                <category android:name=
                    "android.intent.category.DEFAULT" />
               
                <!—
                <category android:name=
                    "android.intent.category.LAUNCHER" />
                -->
            </intent-filter>
        </activity>


The application icon will then no longer appear in the Launcher.

Sunday, July 21, 2013

Windows Phone Tip: Using Schemes to Launch Settings Pages

Due to security reasons, your Windows Phone application is not allowed to modify some of the device’s settings directly. For example, you might want to programmatically turn on the airplane mode on the device. However, this is not allowed without the user’s explicit permission. The only way to turn on airplane mode is for the user to navigate to the Settings’s Airplane Mode page and turn it on manually.

In your application, instead of asking the user to navigate to the Settings page, you can directly bring them to the page, programmatically.

To launch the various Settings pages, you can use the Launcher class with the LaunchUriAsync() method. As you are launching the pages asynchronously, you need to wrap these calls in a async method, like this:

        private async void LaunchSettings(int mode)
        {
            switch (mode)
            {
                case 0: await Launcher.LaunchUriAsync(
                    new Uri("ms-settings-airplanemode:"));
                    break;
                case 1: await Launcher.LaunchUriAsync(
                    new Uri("ms-settings-bluetooth:"));
                    break;
                case 2: await Launcher.LaunchUriAsync(
                    new Uri("ms-settings-cellular:"));
                    break;
                case 3: await Launcher.LaunchUriAsync(
                    new Uri("ms-settings-wifi:"));
                    break;
                case 4: await Launcher.LaunchUriAsync(
                    new Uri("ms-settings-location:"));
                    break;
                case 5: await Launcher.LaunchUriAsync(
                    new Uri("ms-settings-emailandaccounts:"));
                    break;
                case 6: await Launcher.LaunchUriAsync(
                    new Uri("ms-settings-lock:"));
                    break;
            }
        }


The following figure shows the Airplane Mode settings page: