开发者

How do I undo clearPackagePreferredActivities("com.android.launcher");

开发者 https://www.devze.com 2023-03-25 21:35 出处:网络
What I am trying to do is replicate what the ToddlerLock app does.I have managed to clear the default launcher with

What I am trying to do is replicate what the ToddlerLock app does. I have managed to clear the default launcher with

PackageManager localPackageManager = getPackageManager();
localPackageManager.clearPackagePreferredActivities("com.android.launcher");

and then open the launch select dialog with this

Intent i = new Intent();
i.setAction(Inte开发者_如何学Cnt.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i); 

As long as the user checks the "use by default for this action" the home key now sends the user to my app, thus essentially disabling it.

I then use "clearPackagePreferredActivities("com.my_application")" when I exit my app and the user has to choose a new default home app.

My question is how can I choose the default home application (essentially checking the "use by default for this action" check box in code for the "com.android.launcher" package. That way the user does not constantly have to see that dialog box every time they open and close my app.

I think ToddlerLock does this somehow without using clearPackagePreferredActivities because if I look at the "clear defaults" in the application manager it is not cleared and you only have to go through the set as default dialog box one time on startup and once when you exit to set it back to the normal home screen.

Thanks for your help.


I have implemented the same functionality in different way.

  • Let's say you have 'LockScreenAcitivity' configured as Home Screen in Manifest.
  • Launch LockScreenActivity by sending Home Intent.
  • Android will popup a dialog, to select the default Acitivity
  • choose your LockScreenActivity from List as default Activity
  • .....
  • .....
  • While closing the Activity don't clear the prefered Activities.
  • Disable your LockScreenActivity alone by calling PackageManager.setComponentEnabledSetting()
  • After you disable your LockScreenActivity, android will rollback to previous Prefered Activity (that's your old home screen ).

Next time when you launch your app,

  • enable your lockscreenActivity again by calling PackageManager.setComponentEnabledSetting()
  • Launch LockScreenActivity by sending Home Intent.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号