Start instant app from another installable App

北慕城南 提交于 2019-12-02 03:29:17
zavidovych

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());
    }
  });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!