标签:开发 ast .sh ext.get str except manager action name
从自己开发的应用中根据QQ号跳转到QQ应用的聊天界面,实现起来很方便:
即:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("mqqwpa://im/chat?chat_type=wpa&uin="+qqNum+"&version=1")));
qqNum(string型)即是所要跳转的qq号。
不过如果直接写这个代码的话,若本机未安装qq应用,程序会直接go die,所以要加以判断:
if (checkApkExist(this, "com.tencent.mobileqq")){ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("mqqwpa://im/chat?chat_type=wpa&uin="+qqNum+"&version=1"))); }else{ Toast.makeText(this,"本机未安装QQ应用",Toast.LENGTH_SHORT).show(); } break;
方法checkApkExit()如下:
public boolean checkApkExist(Context context, String packageName) { if (packageName == null || "".equals(packageName)) return false; try { ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }
注:qq的应用包名是:com.tencent.mobileqq
标签:开发 ast .sh ext.get str except manager action name
原文地址:http://www.cnblogs.com/zhujiabin/p/7905381.html