android设置多个类似APP其中的一个为默认

05-09 17:01:13.547: I/ActivityManager(3003): START u0 {act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=https://www.baidu.com cmp=android/com.android.internal.app.ResolverActivity} from pid 5222
05-09 17:01:13.587: I/ActivityManager(3003): Start proc system:ui for activity android/com.android.internal.app.ResolverActivity: pid=15544 uid=1000 gids={41000, 3002, 3001, 3003, 1028, 1015, 1023, 1021, 3004, 3005, 1000, 3009, 1010}
05-09 17:01:14.557: I/ActivityManager(3003): Displayed android/com.android.internal.app.ResolverActivity: +975ms
从ActivityManger输出Log可以知道是ResolverActivity处理app选择。
android\frameworks\base\core\java\com\android\internal\app\ResolverActivity.java
protected void onCreate(Bundle savedInstanceState) {
// Use a specialized prompt when we're handling the 'Home' app startActivity()
final int titleResource;
final Intent intent = makeMyIntent();
final Set<String> categories = intent.getCategories();
if (Intent.ACTION_MAIN.equals(intent.getAction())
&& categories != null
&& categories.size() == 1
&& categories.contains(Intent.CATEGORY_HOME)) {
titleResource = com.android.internal.R.string.whichHomeApplication;//选择主屏幕应用
} else {
titleResource = com.android.internal.R.string.whichApplication;//选择要使用的应用:
} onCreate(savedInstanceState, intent, getResources().getText(titleResource),
null, null, true);
}
protected void onCreate(Bundle savedInstanceState, Intent intent,
CharSequence title, Intent[] initialIntents, List<ResolveInfo> rList,
boolean alwaysUseOption) {
setTheme(R.style.Theme_DeviceDefault_Light_Dialog_Alert);
super.onCreate(savedInstanceState);
try {
mLaunchedFromUid = ActivityManagerNative.getDefault().getLaunchedFromUid(
getActivityToken());
} catch (RemoteException e) {
mLaunchedFromUid = -1;
}
mPm = getPackageManager();
mAlwaysUseOption = alwaysUseOption;
mMaxColumns = getResources().getInteger(R.integer.config_maxResolverActivityColumns); AlertController.AlertParams ap = mAlertParams; ap.mTitle = title; mPackageMonitor.register(this, getMainLooper(), false);
mRegistered = true; final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
mIconDpi = am.getLauncherLargeIconDensity();
mIconSize = am.getLauncherLargeIconSize(); mAdapter = new ResolveListAdapter(this, intent, initialIntents, rList, mLaunchedFromUid);//获取APP列表
int count = mAdapter.getCount();
if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) {
// Gulp!
finish();
return;
} else if (count > 1) {
ap.mView = getLayoutInflater().inflate(R.layout.resolver_list, null);
mListView = (ListView) ap.mView.findViewById(R.id.resolver_list);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(this);
mListView.setOnItemLongClickListener(new ItemLongClickListener()); if (alwaysUseOption) {
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
} else if (count == 1) {
startActivity(mAdapter.intentForPosition(0));
mPackageMonitor.unregister();
mRegistered = false;
finish();
return;
} else {
ap.mMessage = getResources().getText(R.string.noApplications);
} setupAlert(); if (alwaysUseOption) {
final ViewGroup buttonLayout = (ViewGroup) findViewById(R.id.button_bar);
if (buttonLayout != null) {
buttonLayout.setVisibility(View.VISIBLE);
mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always);
mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once);
} else {
mAlwaysUseOption = false;
}
// Set the initial highlight if there was a preferred or last used choice
final int initialHighlight = mAdapter.getInitialHighlight();
if (initialHighlight >= 0) {
mListView.setItemChecked(initialHighlight, true);
onItemClick(null, null, initialHighlight, 0); // Other entries are not used
}
}
}
点击“始终”按钮,设置默认程序
public void onButtonClick(View v) {
final int id = v.getId();
startSelected(mListView.getCheckedItemPosition(), id == R.id.button_always);
dismiss();
} void startSelected(int which, boolean always) {
if (isFinishing()) {
return;
}
ResolveInfo ri = mAdapter.resolveInfoForPosition(which);
Intent intent = mAdapter.intentForPosition(which);
onIntentSelected(ri, intent, always);
finish();
} protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {
if (mAlwaysUseOption && mAdapter.mOrigResolveList != null) {
// Build a reasonable intent filter, based on what matched.
IntentFilter filter = new IntentFilter(); if (intent.getAction() != null) {
filter.addAction(intent.getAction());
}
Set<String> categories = intent.getCategories();
if (categories != null) {
for (String cat : categories) {
filter.addCategory(cat);
}
}
filter.addCategory(Intent.CATEGORY_DEFAULT); int cat = ri.match&IntentFilter.MATCH_CATEGORY_MASK;
Uri data = intent.getData();
if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
String mimeType = intent.resolveType(this);
if (mimeType != null) {
try {
filter.addDataType(mimeType);
} catch (IntentFilter.MalformedMimeTypeException e) {
Log.w("ResolverActivity", e);
filter = null;
}
}
}
if (data != null && data.getScheme() != null) {
// We need the data specification if there was no type,
// OR if the scheme is not one of our magical "file:"
// or "content:" schemes (see IntentFilter for the reason).
if (cat != IntentFilter.MATCH_CATEGORY_TYPE
|| (!"file".equals(data.getScheme())
&& !"content".equals(data.getScheme()))) {//注意这里排除了"file://", "content://"
filter.addDataScheme(data.getScheme()); // Look through the resolved filter to determine which part
// of it matched the original Intent.
Iterator<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator();
if (pIt != null) {
String ssp = data.getSchemeSpecificPart();
while (ssp != null && pIt.hasNext()) {
PatternMatcher p = pIt.next();
if (p.match(ssp)) {
filter.addDataSchemeSpecificPart(p.getPath(), p.getType());
break;
}
}
}
Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator();
if (aIt != null) {
while (aIt.hasNext()) {
IntentFilter.AuthorityEntry a = aIt.next();
if (a.match(data) >= 0) {
int port = a.getPort();
filter.addDataAuthority(a.getHost(), port >= 0 ? Integer.toString(port) : null);
break;
}
}
}
pIt = ri.filter.pathsIterator();
if (pIt != null) {
String path = data.getPath();
while (path != null && pIt.hasNext()) {
PatternMatcher p = pIt.next();
if (p.match(path)) {
filter.addDataPath(p.getPath(), p.getType());
break;
}
}
}
}
} if (filter != null) {
final int N = mAdapter.mOrigResolveList.size();
ComponentName[] set = new ComponentName[N];
int bestMatch = 0;
for (int i=0; i<N; i++) {
ResolveInfo r = mAdapter.mOrigResolveList.get(i);
set[i] = new ComponentName(r.activityInfo.packageName, r.activityInfo.name);
if (r.match > bestMatch) bestMatch = r.match;
}
if (alwaysCheck) {
getPackageManager().addPreferredActivity(filter, bestMatch, set, intent.getComponent());//设置默认
} else {
try {
AppGlobals.getPackageManager().setLastChosenActivity(intent,
intent.resolveTypeIfNeeded(getContentResolver()),
PackageManager.MATCH_DEFAULT_ONLY,
filter, bestMatch, intent.getComponent());
} catch (RemoteException re) {
Log.d(TAG, "Error calling setLastChosenActivity\n" + re);
}
}
}
} if (intent != null) {
startActivity(intent);
}
}
android设置多个类似APP其中的一个为默认的更多相关文章
- Android Studio 1.0.2项目实战——从一个APP的开发过程认识Android Studio
Android Studio 1.0.1刚刚发布不久,谷歌紧接着发布了Android Studio 1.0.2版本,和1.0.0一样,是一个Bug修复版本.在上一篇Android Studio 1.0 ...
- Android 4.3实现类似iOS在音乐播放过程中如果有来电则音乐声音渐小铃声渐大的效果
目前Android的实现是:有来电时,音乐声音直接停止,铃声直接直接使用设置的铃声音量进行铃声播放. Android 4.3实现类似iOS在音乐播放过程中如果有来电则音乐声音渐小铃声渐大的效果. 如果 ...
- Android 一个app启动另一个app
最近,一个app启动另一个app,这个玩法挺火的嘛,有没有试过更新QQ到5.1版本,QQ的健康里面就可以添加其他app,实现从QQ跳转到其他app应用.这个挺好玩的,一下子带来了多少流量啊. 一.先来 ...
- Android M 特性 Doze and App Standby模式详解
版权声明:本文由郑桂涛原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/185 来源:腾云阁 https://www.qclo ...
- Android - 分享内容 - 接收其他APP的内容
就象程序可以发送数据给其他程序,所以也可以接收其他程序的数据.想一下用户如何和程序交互,以及想从其他程序接收什么样类型的数据.例如,一个社交程序可能对接收其他程序的文字(比如有趣的网址)感兴趣.Goo ...
- Android - 分享内容 - 给其他APP发送内容
创建一个intent时,必须要指定intent将要触发的操作.Android定义了很多操作,包括ACTION_SEND,就象可以猜到的一样,表示intent是把数据从一个activity发送给另一个, ...
- Android TV开发总结(三)构建一个TV app的焦点控制及遇到的坑
转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼yuiop:http://blog.csdn.net/hejjunlin/article/details/52835829 前言:上篇中,&l ...
- Android TV开发总结(一)构建一个TV app前要知道的事儿
转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼yuiop:http://blog.csdn.net/hejjunlin/article/details/52792562 前言:近年来,智能 ...
- android一个app打开另一个app的指定页面
一个app打开另一个app的指定页面方法 有以下几种 1.通过包名.类名 2.通过intent的 action 3.通过Url 方案1. ComponentName componentName = n ...
随机推荐
- 2. xargs 命令
1.简介 xargs是给命令传递参数的一个过滤器,也是组合多个命令的一个工具.它把一个数据流分割为一些足够小的块,以方便过滤器和命令进行处理.通常情况下,xargs从管道或者stdin中读取数据,但是 ...
- 创建线程方式-GCD
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- php curl vs python提交多维数组+文件
总结: 1.data数据格式 2.php post 格式无需json_encode(关联数组,所以可以绕弯) 参考:http://bbs.csdn.net/topics/390645553?page ...
- 用webview打开网页时,里面有个div带滚动条的,但是在平板上滚动条失效
android2.3的不支持滚动条,并且scrollTop也不支持的.(设置overflow未hidden就可以支持). function noBarsOnTouchScreen(arg) { var ...
- Mac后台开发MNMP(nginx , mysql, php)标配
mysql安装: 方法:1.原始方法,下载压缩文件,解压,安装,配置 2.dmp文件安装 3.brew安装 这里使用brew安装: a.brew ...
- input元素垂直居中
chrome,firefox,safari, ie9+ 会根据高度自动居中文字: IE9- 以下用这段代码垂直居中: input[type="text"] { line-heigh ...
- php中好用的时间函数
//查询数据30天的数据$y=date("Y",time());$m=date("m",time());$d=date("d",time() ...
- 8. js中json格式解析
var doc = O_PARAMETER.FJSonStr;(doc为:{"items":[],"nextId":0}) //1.先转为json对象,主要有以 ...
- 关于新闻,在线编辑器建表时此字段一定要为text
create table about( content text )engine=myisam default charset=utf8; 项目的各个建表语句 create database day4 ...
- tcl使用笔记
tcl语法网站:http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm 1)拷贝文件 set PRJ_HDL_DIR "../prj/hdl&quo ...