设置应用程序的默认主页应用程序、主页

2023-09-08 09:16:53 作者:甜甜的梦都给你

我已将我的应用程序为默认主页,一切都会好的,但如果我设置发射器为默认主页被我的应用程序(错误),那么我的应用程序从不要求设置我的应用程序为默认值,直接打开发射家。我想直到我的应用程序设置为默认主页它要求用户设置为默认。请帮助

I have set my application as default home, Everything is going good but if i set Launcher as default home by my application(by mistake), then my app never ask to set my app as default and directly opens the Launcher home. I want that until my app is set as default home it ask user to set as default. Please help

先谢谢了。

推荐答案

您可以通过这块code的检查当前的默认启动:

You can check current default launcher by this piece of code:

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
    String currentHomePackage = resolveInfo.activityInfo.packageName;

在这个答案显示:How我可以在Android 2.3及以上得到当前发射的包名?

所以,简单地检查是否 currentHomePackage 等于应用的程序包和采取相应的行动。

So simply check if currentHomePackage equals your App's Package and act accordingly.

如果用户设置另一个应用程序为默认启动的对话框选择一个默认的启动只会再次出现,如果他delets的发射器默认设置或删除/安装一个应用程序,可以为默认启动程序行事。

If the user sets another App as Default Launcher the Dialog to choose a Default Launcher would only appear again if he delets the Launchers Defaults or removes/installs an App which can act as default launcher.