安卓:更改默认主页的应用主页

2023-09-12 01:42:59 作者:江山寒色远

对于一些具体要求 我需要改变Android的默认主页的应用 我的自定义主页的应用程序(在我的应用程序的设置,将切换默认首页=我的应用程序或previous家)

for some specific requirement I am required to change Android Default Home application with my customized Home application ( a setting inside my app that will toggle default home = my application or previous home)

我不希望用户出行Android设置是非常复杂的。

I don't want the user to travel android settings that are very complicated.

任何一个可以帮助我喜欢在那里注册launcher.apk违约 家庭应用或者如何更改

Can any one help me out like where it registers launcher.apk for default home application or how to change that

我唯一能找到的是那个老问题:How更改默认的Andr​​oid的桌面应用程序?

The only thing I could find was that old question: How to change default Android's Desktop application?

但没有答案。

我看到HomeSwitcher在做的伎俩市场,但没有答案的开发商可能确实很忙。

I have seen HomeSwitcher in the Market that do the trick, but no answer for the developer that might certainly be busy.

修改

我发现这个在网络上http://www.mail-archive.com/android-developers@googlegroups.com/msg74167.html

但我得到了同样的问题:

But I got the same issue:

这是我的code:

    private void makePreferred() {
            PackageManager pm = getPackageManager();
            IntentFilter f = new IntentFilter("android.intent.action.MAIN");
            f.addCategory("android.intent.category.HOME");
            f.addCategory("android.intent.category.DEFAULT");
            ComponentName cn = new ComponentName("com.example.android.home", "com.example.android.home.Home");
            pm.addPreferredActivity(f, IntentFilter.MATCH_CATEGORY_EMPTY, null, cn);

我有 android.permission.SET_ preFERRED_APPLICATIONS 的设置 表现。在执行上面的code后,日志声称事情已经 被添加像预期的(相同的日志,当我勾选设置为默认 从IntentResolver的列表)。然而,当我继续通过点击回家, 列表中仍然显示和记录说:

I have the android.permission.SET_PREFERRED_APPLICATIONS set in the manifest. After executing the code above, the logs claim things have been added like expected (same logs as when I tick off "Make default" from IntentResolver's list). However, when I proceed by clicking home, the list still shows up and the logs say:

INFO/PackageManager(52): Result set changed, dropping preferred
activity for Intent { act=android.intent.action.MAIN cat=
[android.intent.category.HOME] flg=0x10200000 } type null

如此看来解析器删除默认项。我做 做错了事,或者这是一种安全措施?什么想法 这背后?

So it seems the resolver deletes the default entry. Am I doing something wrong, or is this a security measure? What are the ideas behind this?

推荐答案

我做的和广泛的研究,从2.2开始,就没有办法做到这一点。唯一的办法就是使用一些黑客的孩子锁的应用程序,但没有这个程序,把三星手机最近在无限循环,所以它是一个冒险的做法。

I did an extensive research on that and starting from 2.2 there is no way to do that. The only way is using some hacking that toddler lock app does but this app put samsung phones recently in the infinite loop, so it is a risky approach.

如果你看一下升级Froyo源$ C ​​$ C 此处 packagemanager类的,你会看到这个小环境中添加preferredActivity方式:

if you look at the froyo source code here of packagemanager class, you will see this small condition in the addPreferredActivity method:

if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid())
                     < Build.VERSION_CODES.FROYO) {
                 Slog.w(TAG, "Ignoring addPreferredActivity() from uid"
                        + Binder.getCallingUid());
                 return;
             }

HomeSwitcher不能在2.2正常工作,因为它使用这个非常的方法和开发商在做应用页面评论的不支持升级Froyo(2.2) 由于API的变化的

HomeSwitcher does not work properly on 2.2 since it uses this very method and developer made a comment on app page "Froyo(2.2) is not supported due to the API change"