打开第三方Activity前判断Intent能否被解析
来源:互联网 发布:ocr文字识别软件mac版 编辑:程序博客网 时间:2024/04/30 01:45
在自己的应用程序中利用第三方应用程序的Activity和Service是十分方便的,但是你无法保证用户设备上安装了特定的某个应用软件,或者设备上有能够处理你的Intent请求的程序。
因此,在启动第三方APK里的Activity之前,确定调用是否可以解析为一个Activity是一种很好的做法。
通过Intent的resolveActivity方法,并想该方法传入包管理器可以对包管理器进行查询以确定是否有Activity能够启动该Intent:
// Create the impliciy Intent to use to start a new Activity.Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:555-2368"));// Check if an Activity exists to perform this action.PackageManager pm = context.getPackageManager();ComponentName cn = intent.resolveActivity(pm);if (cn == null) { // If there is no Activity available to perform the action // Check to see if the Google Play Store is available. Uri marketUri = Uri.parse("market://search?q=pname:com.myapp.packagename"); Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(marketUri); // If the Google Play Store is available, use it to download an application // capable of performing the required action. Otherwise log an error. if (marketIntent.resolveActivity(pm) != null) { context.startActivity(marketIntent); } else { Log.d(TAG, "Market client not available."); }} else{ context.startActivity(intent);}
2 0
- 打开第三方Activity前判断Intent能否被解析
- 隐式调用第三方Activity前判断Intent
- Android启动Activity前确定Intent 能否解析
- Android启动Activity前确定Intent 能否解析
- 如何解析第三方Intent
- Android通过Intent判断程序是否安装及通过第三方打开
- 验证Intent能否解析
- 【intent】确定Intent能否解析
- 通过Intent 调用第三方Activity未成功
- 第三方登录-------activity
- 打开第三方应用
- 打开第三方应用程序
- 打开第三方应用
- 打开第三方应用
- Activity 、Intent深入解析
- Activity 、Intent深入解析
- 解析Activity、Intent、Service
- Activity 、Intent深入解析
- php学习之路之apache的安装
- 用PHP的 sockopen方式发送POST 或GET请求
- PacakgeManagerService学习笔记七-APK installation
- 50万用户够不够
- 我们的爱情快乐
- 打开第三方Activity前判断Intent能否被解析
- 开启战斗模式
- codeforces 388C Fox and Card Game
- 产品经理知识梳理(1)-产品构思基本原则
- 用C++11实现spinlock
- java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory的解决
- openvas 6版本,迁移到colinux版本
- hdu 1116 欧拉路
- 2014年值得关注的10个开源项目(上)