手機要不要裝微信?判斷手機是否裝了微信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;
}
,下面我們就來聊聊關于手機要不要裝微信?接下來我們就一起去了解一下吧!
判斷手機是否裝了微信
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;
}
2.加入代碼
Intent intent = new Intent();
ComponentName cmp=newComponentName("com.tencent.mm","com.tencent.mm.ui.LauncherUI");
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(cmp);
startActivity(intent);
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!