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
Android系统中的PackageManager(包管理器)是一个系统级别的服务,它是一个应用程序包的管理器,可以用来安装、卸载、查询应用程序包信息等操作。PackageManager API是Android系统中非常重要的一个API,它可以让开发者获取应用程序包的信息,比如版本号、权限等等。 常用的PackageManager命令有: 1. 查询已安装应用的信息 ``` pm list packages // 列出所有已安装的应用的包名 pm list packages -s // 列出所有已安装的系统应用的包名 pm list packages -3 // 列出所有已安装的第三方应用的包名 pm list packages -f // 列出所有已安装应用的APK路径 pm list packages -d // 只列出已禁用的应用 pm list packages -e // 只列出系统已启用的应用 ``` 2. 安装应用 ``` pm install /path/to/app.apk // 安装应用 pm install -r /path/to/app.apk // 重新安装应用,保留应用数据 pm install -t /path/to/app.apk // 允许安装覆盖其他应用 pm install -i <installer_package_name> /path/to/app.apk // 指定应用安装包的安装来源 ``` 3. 卸载应用 ``` pm uninstall com.package.name // 卸载应用 pm uninstall -k com.package.name // 卸载应用,保留应用数据和缓存 ``` 4. 查询应用信息 ``` pm dump com.package.name // 输出应用信息 pm path com.package.name // 输出应用APK路径 pm list features // 列出系统支持的特性 pm list instrumentation // 列出所有已安装的Instrumentation ``` 5. 其他命令 ``` pm enable com.package.name // 启用应用 pm disable com.package.name // 禁用应用 pm clear com.package.name // 清除应用数据和缓存 ``` 以上是一些常用的PackageManager命令,使用时需要注意权限问题,部分命令需要root权限才能执行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值