Hide application icon

前端 未结 5 1798
广开言路
广开言路 2020-12-01 02:58

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 the

5条回答
  •  广开言路
    2020-12-01 03:57

    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

         
    

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

提交回复
热议问题