我想在Google Fit Syncronize中打开MiFit应用程序,但我遇到了麻烦。如何打开按钮?
这是我的代码:
@OnClick(R.id.div_mi_band)
public void miBandIntegration() {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.xiaomi.hm.health.thirdbind",".thirdbind.ThirdBindActivity"));
startActivity(intent);
}
答案 0 :(得分:0)
尝试一下。
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.xiaomi.hm.health.thirdbind");
if (launchIntent != null) {
startActivity(launchIntent);//null pointer check in case package name was not found
}
答案 1 :(得分:0)
尝试以下方法:
try{
boolean isAppInstalled = isPackageInstalled(MainActivity.this,"com.xiaomi.hm.health");
if (isAppInstalled) {
Intent navigationIntent = new Intent();
navigationIntent.setPackage("com.xiaomi.hm.health");
startActivity(navigationIntent);
}else{
Toast.makeText(MainActivity.this,"MI Fit is not currently installed",Toast.LENGTH_SHORT).show();
}
}catch (Exception e){
Toast.makeText(MainActivity.this,"MI Fit Application is not currently installed",Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
要检查是否已安装应用程序:
public static boolean isPackageInstalled(Context context, String packageName) {
final PackageManager packageManager = context.getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
if (intent == null) {
return false;
}
List <ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return !list.isEmpty();
}
根据需要更改软件包名称。
希望它对您有用。