Nova如何管理这个?我真的试图做同样的事情:为用户提供一个按钮来清除并选择他们的新默认启动器.
我可以获取默认的应用名称并显示它:
private String getPrefered(Intent i) {
PackageManager pm = this.getActivity().getPackageManager();
final ResolveInfo mInfo = pm.resolveActivity(i, 0);
return (String) pm.getApplicationLabel(mInfo.activityInfo.applicationInfo);
}
Run Code Online (Sandbox Code Playgroud)
这里Intent i是
Intent home = new Intent("android.intent.action.MAIN");
home.addCategory("android.intent.category.HOME");
Run Code Online (Sandbox Code Playgroud)
然后我调用系统ResolveActivity,
private void makePrefered() {
Intent selector = new Intent("android.intent.action.MAIN");
selector.addCategory("android.intent.category.HOME");
selector.setComponent(new ComponentName("android", "com.android.internal.app.ResolverActivity"));
startActivity(selector);
}
Run Code Online (Sandbox Code Playgroud)
选择器出现并正常运行,但它实际上并未设置或清除任何值.在调试时,似乎我错过了一些额外的东西?当我调用该makePrefered方法时,我收到以下日志消息,
I/ActivityManager( 602): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] cmp=android/com.android.internal.app.ResolverActivity u=0} from pid 22641
Run Code Online (Sandbox Code Playgroud)
当我使用Nova实现时,我看到了所有这些,
I/PackageManager( 602): Result set changed, dropping preferred activity for Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 (has extras) } type null …Run Code Online (Sandbox Code Playgroud) 可能重复:
Android:更改默认主页应用程序
我想创建一个像" Home Switcher "这样的程序,可以通过编程方式设置默认启动器.我还没有编写代码,但可以找出如何找到可用的启动器应用程序,但我不知道如何以编程方式设置默认值.谁能指出我正确的方向?