Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide application icon

I am doing an Android application. I want to hide the application icon in the emulator and I want to start my application by pressing some numbers, for instance 456#. Is there a way to do this?

like image 917
sarath Avatar asked Dec 06 '11 10:12

sarath


People also ask

How do I hide app icons?

Here, we'll show you how to hide apps on Android on a Samsung Galaxy S21. First, open Settings, tap Home screen, and scroll to Hide apps. Tap the apps you want to hide, and they'll move to the Hidden apps section.

How do I hide an app on my PC?

Right-click on the app name and choose Hide from the Programs and Features list. If you want to hide all the apps, click on Edit and choose Select All. Right-click on any app name and choose Hide from the Programs and Features list.


2 Answers

To Hide app icon from launcher programatically you can do this

    PackageManager packageManager = context.getPackageManager();
    ComponentName componentName = new ComponentName(context,
            LauncherActivity.class);
    packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);

To launch app by pressing number first add folowing permission in mainfest file

     <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

Then register receiver

<receiver android:name=".LaunchAppViaDialReceiver"> 
    <intent-filter> 
    <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
    </intent-filter> 
</receiver>

Then create a receiver class

  public class LaunchAppViaDialReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Bundle bundle = intent.getExtras();
    if (null == bundle)
        return;
    String phoneNubmer = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
             //here change the number to your desired number
    if (phoneNubmer.equals("12345")) {
        setResultData(null);
        Gaurdian.changeStealthMode(context,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
        Intent appIntent = new Intent(context, LauncherActivity.class);
        appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(appIntent);
    }

}
like image 67
IMA Avatar answered Sep 27 '22 20:09

IMA


If you want to hide the app icon it's a good idea to show the icon first and let the user know how to start the app once the icon is gone. First create an activity-alias in the manifest and move your intent filter there. This way you can disable the icon without disabling the activity.

<activity
    android:name=".MainActivity"
    android:label="@string/app_name" >
</activity>
<activity-alias
    android:name=".Launcher" 
    android:targetActivity=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter> 
</activity-alias>

Get the component name of the launcher alias using your package name:

private static final ComponentName LAUNCHER_COMPONENT_NAME = new ComponentName(
            "your.package.name", "your.package.name.Launcher");

You can check if it's already disabled...

private boolean isLauncherIconVisible() {
    int enabledSetting = getPackageManager()
            .getComponentEnabledSetting(LAUNCHER_COMPONENT_NAME);
    return enabledSetting != PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
}

...and disable it when appropriate after giving the user information:

private void hideLauncherIcon() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Important!");
    builder.setMessage("To launch the app again, dial phone number 12345.");
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            getPackageManager().setComponentEnabledSetting(LAUNCHER_COMPONENT_NAME,
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
        }
    });
    builder.setIcon(android.R.drawable.ic_dialog_alert);
    builder.show();
}

To launch from the dialer create a broadcast receiver:

public class LaunchViaDialReceiver extends BroadcastReceiver {

    private static final String LAUNCHER_NUMBER = "12345";

    @Override
    public void onReceive(Context context, Intent intent) {
        String phoneNubmer = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        if (LAUNCHER_NUMBER.equals(phoneNubmer)) {
            setResultData(null);
            Intent appIntent = new Intent(context, MainActivity.class);
            appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(appIntent);
        }
    }
}

Add it to the manifest:

<receiver android:name=".LaunchViaDialReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>
</receiver>

And add the permission to the manifest:

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
like image 28
Adam Nybäck Avatar answered Sep 27 '22 22:09

Adam Nybäck