android 应用可以定义多个theme,android设置多个类似APP其中的一个为默认

public voidonButtonClick(View v) {final int id =v.getId();

startSelected(mListView.getCheckedItemPosition(), id==R.id.button_always);

dismiss();

}void startSelected(int which, booleanalways) {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, booleanalwaysCheck) {if (mAlwaysUseOption && mAdapter.mOrigResolveList != null) {//Build a reasonable intent filter, based on what matched.

IntentFilter filter = newIntentFilter();if (intent.getAction() != null) {

filter.addAction(intent.getAction());

}

Set 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 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 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= newComponentName[N];int bestMatch = 0;for (int i=0; i

ResolveInfo r=mAdapter.mOrigResolveList.get(i);

set[i]= newComponentName(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);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值