PackageManager-->resolveActivity查询是否有符合条件的Activity

 

Java代码 复制代码
  1. Intent intent = new Intent(Intent.ACTION_VIEW);  
  2.             intent.setDataAndType(Uri.parse(url), mimetype);  
  3.             if (getPackageManager().resolveActivity(intent,  
  4.                         PackageManager.MATCH_DEFAULT_ONLY) != null) {  
  5.                 // someone knows how to handle this mime type with this scheme, don't download.  
  6.                 try {  
  7.                     startActivity(intent);  
  8.                     return;  
  9.                 } catch (ActivityNotFoundException ex) {  
  10.                     if (Config.LOGD) {  
  11.                         Log.d(LOGTAG, "activity not found for " + mimetype  
  12.                                 + " over " + Uri.parse(url).getScheme(), ex);  
  13.                     }  
  14.                       
  15.                 } 
Intent intent = new Intent(Intent.ACTION_VIEW);              intent.setDataAndType(Uri.parse(url), mimetype);              if (getPackageManager().resolveActivity(intent,                          PackageManager.MATCH_DEFAULT_ONLY) != null) {                  // someone knows how to handle this mime type with this scheme, don't download.                  try {                      startActivity(intent);                      return;                  } catch (ActivityNotFoundException ex) {                      if (Config.LOGD) {                          Log.d(LOGTAG, "activity not found for " + mimetype                                  + " over " + Uri.parse(url).getScheme(), ex);                      }                                        }

查询是否有符合Uri.parse(url), mimetype这两个条件的Activity

public abstract ResolveInfo resolveActivity (Intent intent, int flags)

Since: API Level 1
Determine the best action to perform for a given Intent. This is how resolveActivity(PackageManager) finds an activity if a class has not been explicitly specified.
Parameters
intent An intent containing all of the desired specification (action, data, type, category, and/or component).
flags Additional option flags. The most important is MATCH_DEFAULT_ONLY, to limit the resolution to only those activities that support the CATEGORY_DEFAULT.
Returns
Returns a ResolveInfo containing the final activity intent that was determined to be the best action. Returns null if no matching activity was found.
See Also
MATCH_DEFAULT_ONLY
GET_INTENT_FILTERS
GET_RESOLVED_FILTER
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值