简体   繁体   中英

how can i recall a hidden app from phone dialer?

我的最终项目要求必须隐藏该应用程序,除非在电话拨号器中输入一些代码(例如:*123#),否则永远不要再打开它,你能帮我完成这项任务吗?

This is a bit tricky and it has its up and downs, but what you need to do basically is:

  1. On app install, you need to programmatically disable the app Icon so you cannot open it manually.
  2. Have a BroadcastReceiver registered with the PROCESS_OUTGOING_CALLS intent filter (don't forget to set the uses-permissions ).
  3. In the receiver, listen for every dialed number and when it matches yours you need to activate the App Icon again and then you start the activity with possibly extra data to handle it later.
  4. After processing the data in your activity remember to deactivate the icon again.

To programmatically disable the icon use:

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

To enable it:

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

In your receiver to get the dialed number you need to use:

if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
     String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

     // Validate and start your activity here
     // To start an activity from a receiver you need to use the flag FLAG_ACTIVITY_NEW_TASK in your intent
}

Note: After hiding the icon programmatically you might want to finish() the activity so it closes automatically at first run.

PS I have a working sample of this, so rest assured as I have tested it actually works, sadly I cannot spoon feed you in your final project. Don't hesitate to ask anything tho. Good luck

There is no such functionality in Android. You may be able to do it with a custom home screen, but there is no "hide this app" functionality in the default launcher.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM