| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1544 人关注过本帖
标题:Android用代码打开系统设置->桌面设置的Activity遇上问题
只看楼主 加入收藏
szuzsq
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-5-6
收藏
 问题点数:0 回复次数:0 
Android用代码打开系统设置->桌面设置的Activity遇上问题
我项目中有个需求,只需要能打开系统设置中切换桌面launcher的界面,让用户选择就行了。不需要直接切换。
如果手动打开的话。
1).华为Android5.1.1路径:设置->应用管理->默认应用设置->桌面
2).华为Android6.0路径:   设置->应用管理->高级->默认应用设置->桌面

打开的界面如下图:
图片附件: 游客没有浏览图片的权限,请 登录注册



我用代码,想打开这个界面,我的代码如下:


public void startHuaweiSettingActOfDefLauncher() {
    IntentFilter preferred_app_intent_filter = new IntentFilter();
    preferred_app_intent_filter.addAction(Intent.ACTION_MAIN); //android.intent.action.MAIN
    preferred_app_intent_filter.addCategory(Intent.CATEGORY_HOME); //android.intent.category.HOME
   
    Intent preferred_app_intent = new Intent(Intent.ACTION_MAIN);
    preferred_app_intent.addCategory(Intent.CATEGORY_HOME);
   
    Intent intent = new Intent();
    //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClassName("com.android.settings", "com.android.settings.Settings$PreferredSettingsActivity");
    intent.putExtra("preferred_app_label", "桌面");
    intent.putExtra("preferred_app_type", "PREFERRED_HOME");
    intent.putExtra("preferred_app_package_name", getPackageName());
    //intent.putExtra("preferred_app_class_name", MainActivity.class.getName());
    //intent.putExtra("is_user_confirmed", true);
    intent.putExtra("preferred_app_intent", preferred_app_intent);
    intent.putExtra("preferred_app_intent_filter", preferred_app_intent_filter);
    startActivity(intent);
}

问题来了,上面代码,在Android5.1.1上能打开,在Android6.0上不能打开。

我试着从手机设置那里打开这个界面(即Android5.1.1为:设置->应用管理->默认应用设置->桌面;Android6.0为:   设置->应用管理->高级->默认应用设置->桌面),以及用代码在Android5.1.1下打开这个界面。
之后在命令行下分别输入:


//Android5.1.1系统设置中打开
adb shell dumpsys activity top >android5.txt

//Android6.0系统设置中打开
adb shell dumpsys activity top >android6.txt

//Android5.1.1代码中打开
adb shell dumpsys activity top >android5_ABTest.txt


获得的文件比较大,只截取一部分(完整的文件可以从链接中下载,我看不太懂)。其中红色框出来的,应该是调用参数(即调用方式),看起来系统设置中Android5.1.1,系统设置中Android6.0,和我的代码,调用参数是一样的啊。为什么代码只能在Android5.1.1上有效呢?

全部文件在:
http://

//Android5.1.1系统设置中打开
图片附件: 游客没有浏览图片的权限,请 登录注册


//Android6.0系统设置中打开
图片附件: 游客没有浏览图片的权限,请 登录注册


//我的代码在Android5.1.1中使用
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 代码 打开 系统 桌面 应用 
2018-09-22 15:09
快速回复:Android用代码打开系统设置->桌面设置的Activity遇上问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015815 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved