0

I want to open the MiFit app, in the Google Fit Syncronize, but i'm getting erros. How can i open clicking in a button?

Here is my code:

@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);
}
  • 1
    Possible duplicate of [How to start activity in another application?](https://stackoverflow.com/questions/2209513/how-to-start-activity-in-another-application) – hemen May 27 '19 at 18:16

2 Answers2

0

Try this.

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.xiaomi.hm.health.thirdbind");
if (launchIntent != null) { 
    startActivity(launchIntent);//null pointer check in case package name was not found
}
Koushik Mondal
  • 865
  • 7
  • 15
  • "com.xiaomi.hm.health.thirdbind" is your package name correct and does have a launch activity for this application? Then it should work. – Koushik Mondal May 28 '19 at 05:09
0

Try below:

            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();
            }

To Check App is installed or not:

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();
    }

Change Package name according to need.

I hope its work for you.

Android Geek
  • 8,956
  • 2
  • 21
  • 35