startActivity前resolveActivity的情况
2015-08-03 09:11
417 查看
当启动第三方APP的Activity的时候,不能确定当前手机是否安装了该第三方应用程序,此时应该在startActivity前对启动的intent做一次判断,是否存在匹配的Activity供启动,示例如下(代码来自网络):
// 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); }
相关文章推荐
- Android 第三方应用接入微信平台研究情况分享(二)
- Android 第三方应用接入微信平台研究情况分享(一)
- Android应用内调用第三方应用的方法
- 什么是手机APP?
- ubuntu在utinity使用第三方应用
- Android微信第三方登录接入
- 美化代码的15个代码语法高亮工具
- OAuth 2.0 详细介绍
- Android 5.0:谷歌在数据和设计间取得平衡
- 手机170号段银行不识别 运营商称正努力解决
- 浅谈Android中微信第三方登陆
- 手把手教你如何通过OAuth2.0新浪开放平台认证新浪用户-java
- 第三方SDPieProgressView 下拉刷新tableView
- Google正式开始推送 Android 5.0 Lollipop
- 分享成功后返回出现两个默认应用
- 代号为“柠檬芝士蛋糕”或是“柠檬酥皮派”的Android 5.0,会有什么新的特点?
- IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。
- 初探NDK——移动客户端开发之跨平台
- Android开发,在一个项目中调用(启用)已经安装的第三方apk应用软件
- 工作2-3年的人在前端技能上趋于稳定