/**
* 判断 用户是否安装微信客户端
*/
public static boolean isWeixinAvilible(Context context) {
final PackageManager packageManager = context.getPackageManager();// 获取packagemanager
List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);// 获取所有已安装程序的包信息
if (pinfo != null) {
for (int i = 0; i < pinfo.size(); i++) {
String pn = pinfo.get(i).packageName;
if (pn.equals("com.tencent.mm")) {
return true;
}
}
}
return false;
}
/**
* 判断 用户是否安装QQ客户端
*/
public static boolean isQQClientAvailable(Context context) {
final PackageManager packageManager = context.getPackageManager();
List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
if (pinfo != null) {
for (int i = 0; i < pinfo.size(); i++) {
String pn = pinfo.get(i).packageName;
LogUtils.e("pn = "+pn);
if (pn.equalsIgnoreCase("com.tencent.qqlite") || pn.equalsIgnoreCase("com.tencent.mobileqq")) {
return true;
}
}
}
return false;
}
if(isWeixinAvilible(this)) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
startActivity(intent);
}else{
Toast.makeText(this, "您还没有安装微信,请先安装微信客户端",Toast.LENGTH_SHORT).show();
}
跳转微信只需要加上如上代码即可:
原理就是判断手机中是否存在微信或QQ的包名