Android 使用包名即可打开应用, 当然你也可以自己打印所有报名获取包名,总结下分享平台的包名:
微信:com.tencent.mm
QQ: com.tencent.mobileqq
微博: com.sina.weibo
FACEBOOK: com.facebook.katana
TWITTER: com.twitter.android
instagram: com.instagram.android
如何打开:
/**
* 判断应用是否已安装
*
* @param context
* @param packageName
* @return
*/
public static boolean isInstalled(Context context, String packageName) {
boolean hasInstalled = false;
PackageManager pm = context.getPackageManager();
List<PackageInfo> list = pm
.getInstalledPackages(PackageManager.PERMISSION_GRANTED);
for (PackageInfo p : list) {
//print all package
LogUtils.i("p.packageName===" + p.packageName);
if (packageName != null && packageName.equals(p.packageName.toString())) {
hasInstalled = true;
break;
}
}
return hasInstalled;
}
Open:
public static void openCLD(String packageName, Context context) {
PackageManager packageManager = context.getPackageManager();
PackageInfo pi = null;
try {
pi = packageManager.getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
ToastFactory.showToast(context, "packageNameNotFound");
}
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
resolveIntent.setPackage(pi.packageName);
List<ResolveInfo> apps = packageManager.queryIntentActivities(resolveIntent, 0);
ResolveInfo ri = apps.iterator().next();
if (ri != null) {
String className = ri.activityInfo.name;
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
ComponentName cn = new ComponentName(packageName, className);
intent.setComponent(cn);
context.startActivity(intent);
}
}