【Android】判断某个App是否安装并启动(queryIntentActivities),
2013-10-29 19:49
579 查看
Finding out if an intent is available
Sometimes you want to find if an application has registered for a certain intent. For example you want to check if a certain receiver is available and if you enable some functionality in your app.某些时候你想要知道某个AP是否有注册了一个明确的intent,比如说你想要检查某个receiver是否存在,然后根据是否存在来这个receiver来在你的AP里面enable某些功能
This can be done via checking the PackageManager. The following code checks if an intent exists. You can check via this method for intent and change your application behavior accordingly for example disable or hide menu items.
我们可以通过PackageManager来check它,下面的代码检测了一个intent是否存在.
public boolean isIntentAvailable(Context context, String action) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfo.size() > 0) { return true; } return false; }
第三方传参url启动视频播放器:
Uri uri = Uri.parse(app.getVideoURL()); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "video/mp4"); if (isCallable(intent)) { startActivity(intent); } else { startActivity(new Intent(Intent.ACTION_VIEW, uri)); } private boolean isCallable(Intent intent) { List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
相关文章推荐
- 网页判断判断是否安装APP并启动,没有安装就跳转到下载页面
- android开发 判断app是否是第一次安装
- Android判断是否安装某App
- Android小练习:过渡动画,引导页,判断是否第一次启动App
- Android判断是否安装某App
- Android 判断app是否安装
- Android判断APP是否第一次启动
- Android 根据包名判断app是否安装
- Android 判断app是否安装
- Android判断APP是否第一次启动
- Android 判断app是否第一次安装。
- 安卓随手笔记四:(判断第三方app是否安装并启动)
- Android 判断app是否安装
- android判断APP是否已经安装
- Android 判断app是否安装
- unity3d 判断是否安装指定app android and ios
- 判断Intent是否安全的方法queryIntentActivities的使用
- Android 判断APP是否安装和引导下载实现
- Android判断APP是否第一次启动
- Android 判断程序是否已安装 & 启动另一个程序