Skip to content Skip to sidebar Skip to footer

Start Instant App From Another Installable App

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 google

Solution 1:

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).

InstantAppIntentDataintentData= InstantApps
    .getLauncher(MainActivity.this)
    .getInstantAppIntentData("https://vimeo.com/148943792", null);
intmatchResult= 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()) {
      LaunchDatadata= task.getResult();
      IntentlaunchIntent= 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());
    }
  });

Post a Comment for "Start Instant App From Another Installable App"