Hide application icon from launcher [duplicate]

2019-06-14 23:53发布

问题:

This question already has an answer here:

  • How to Hide app from launcher in Android [duplicate] 1 answer
  • Android how to programmatically hide launcher icon 3 answers

I have an android application. I want to hide app icon from launcher screen & make it visible again after dialing some no i.e "1234" . Any helpful code snippet will be appreciated.

回答1:

Have a look on this link. May be it will help you

hidden App

Edit 1:

First:

PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

Second :

public class DialBroad extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        if ((phoneNumber).equals("123456")) {
            Intent appIntent = new Intent(context, MainActivity.class);
            appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(appIntent);
            setResultData(null);
        } else {
            // Toast.makeText(context, phoneNumber, Toast.LENGTH_LONG).show();
        }
    }
}