我想检测是否在Android上安装了腾讯(微博)应用程序,还是没有以编程方式安装。
以下是我正在使用的代码:
boolean installed_tweibo = appInstalledOrNot(" com.tencent.weibo");
if(installed_tweibo) {
Intent intent = new Intent(SplashActivity.this, Main1Activity.class);
startActivity(intent);
finish();
} else {
Intent intent = new Intent(SplashActivity.this, Main2Activity.class);
startActivity(intent);
finish();
}
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
但" com.tencent.weibo"是不正确的。
我想知道腾讯(微博)应用的正确包名。
请帮帮我。
答案 0 :(得分:1)
正确的微博包名称为“com.sina.weibo”。
public static boolean openApp(Context context, String packageName) {
PackageManager manager = context.getPackageManager();
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new PackageManager.NameNotFoundException();
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
return true;
}
输入软件包名称并执行检查,如果您安装了微博,它将打开微博。
答案 1 :(得分:0)
您可以使用此功能检查用户是否安装了应用程序:
public boolean isPackageInstalled(String application) {
PackageManager pm = getApplicationContext().getPackageManager();
try {
pm.getPackageInfo(application, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
因此,在您的活动中,您只需致电:
boolean isWeiboInstalled = isPackageInstalled("com.tencent.weibo");
答案 2 :(得分:0)
boolean installed_tweibo = appInstalledOrNot("com.tencent.WBlog");