Start instant app from another installable App

前端 未结 1 1863
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 05:19

I need to start an Instant App from another installable app I own. The idea is really this, a sync app that starts other instant apps. I\'ve already posted my instant app on goo

1条回答
  •  遥遥无期
    2021-01-25 06:14

    It fails because of setPackage() in your snippet. Just send a VIEW + BROWSABLE intent for given URL and it will launch an instant app if it's available on this device (it will fall back to browser otherwise).

    If you want to guarantee that instant app will launch you can use this API to check if instant app is available on device first Google APIs for Android Documentation:- API for launching instant apps

    This will take care of the case where instant app cannot run on device because OS is too old, or because user is opted out, or intant app is unavailable in a given country.

    You can also use it to get metadata about the instant app before launching it (such as icon or title).

    InstantAppIntentData intentData = InstantApps
        .getLauncher(MainActivity.this)
        .getInstantAppIntentData("https://vimeo.com/148943792", null);
    int matchResult = intentData.getMatchResult();
    if (matchResult == RESULT_LAUNCH_OK) {
      Log.i(TAG, "Launching instant: " + intentData.getPackageName());
      startActivity(intentData.getIntent());
    } else {
      Log.i(TAG, "Match result: " + matchResult);
    }
    
    InstantApps
      .getLauncher(MainActivity.this)
      .getInstantAppLaunchData("https://vimeo.com/148943792")
      .addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
          LaunchData data = task.getResult();
          Intent launchIntent = data.getIntent();
          if (launchIntent != null) {
            Log.i(TAG, "App label: " + data.getApplicationLabel());
            Log.i(TAG, "Package: " + data.getPackageName());
            Log.i(TAG, "Icon width: " + data.getApplicationIcon().getWidth());
            startActivity(launchIntent);
          } else {
            Log.i(TAG, "No instant app found");
          }
        } else {
          Log.i(TAG, "Error: " + task.getException());
        }
      });
    

    0 讨论(0)
提交回复
热议问题