Hide application icon

sarath picture sarath · Dec 6, 2011 · Viewed 25.4k times · Source

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?

Answer

IMA picture IMA · Jul 25, 2012

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);
    }

}