3

The app in the play store currently is configured to handle https://www.example.com/hello/in an intent filter to launch an activity and showInstallPrompt(...) is supposed to launch the activity once installation of the app is finished.

https://developer.android.com/topic/instant-apps/reference.html#public_methods

showInstallPrompt(...) Docs:

Shows a dialog that allows the user to install the current instant app. This method is a no-op if the current running process is an installed app. You must provide a post-install intent, which the system uses to start the application after install is complete.

postInstallIntent Docs:

The intent to launch after the instant app has been installed. This intent must resolve to an activity in the installed app package, or it will not be used.

I've tried doing this:

Uri uri = Uri.parse("https://www.example.com/hello/");
Intent postInstallIntent = new Intent("action", uri);
InstantApps.showInstallPrompt(MainActivity.this, postInstallIntent, 0, "InstantApp");

and this

Intent postInstallIntent = new Intent("https://www.example.com/hello/");
InstantApps.showInstallPrompt(MainActivity.this, postInstallIntent, 0, "InstantApp");

and this

Intent postInstallIntent = new Intent(Intent.ACTION_VIEW,
        Uri.parse("https://www.example.com/hello/"))
        .addCategory(Intent.CATEGORY_DEFAULT)
        .addCategory(Intent.CATEGORY_BROWSABLE);

It brings me the the play store, but neither launches the app automatically once the install is completed.

mco
  • 1,809
  • 15
  • 31
  • please have a look on URL https://developer.android.com/topic/instant-apps/faqs.html , if i understand correctly , you have install app in device and then you trying to do this, can check after uninstall apk if installed. – Prags Dec 02 '17 at 07:25
  • I had trouble forming the Intent. Thanks to your examples, I found the first one worked to enable showInstallPrompt() for me. – JAW Mar 27 '18 at 19:51

1 Answers1

2

Please have a look at:
https://github.com/googlesamples/android-instant-apps/tree/master/install-api
and
https://github.com/googlesamples/android-instant-apps/blob/master/install-api/features/install/src/main/java/com/instantappsamples/feature/install/InstallApiActivity.kt

  • This sample app demonstrates how to use the Install API. The API triggers the Intent to install the app on device.
  • The call also accepts the Intent, which is triggered after the installation is complete.
  • The sample also shows the correct structure to implement showInstallPrompt method along with postInstallIntent.

Refer the sample code snippet:

private val postInstallIntent = Intent(Intent.ACTION_VIEW,
        Uri.parse("https://install-api.instantappsample.com/")).
        addCategory(Intent.CATEGORY_BROWSABLE).
        putExtras(Bundle().apply {
            putString("The key to", "sending data via intent")
        })

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_install)

    val isInstantApp = InstantApps.isInstantApp(this)

    findViewById<Button>(R.id.start_installation).apply {
        isEnabled = isInstantApp
        // Show the installation prompt only for an instant app.
        if (isInstantApp) {
            setOnClickListener {
                InstantApps.showInstallPrompt(this@InstallApiActivity,
                        postInstallIntent,
                        REQUEST_CODE,
                        REFERRER)
            } }
    } }
ManmeetP
  • 801
  • 7
  • 17
  • I tried that too, but it still doesn't do anything. I tested the intent filter on my original app multiple times and it is working. – mco Dec 07 '17 at 02:32
  • If it still doesn't work for you then I would suggest you to submit your project to Google's [issuetracker](https://issuetracker.google.com/issues). They will take a look at it. (also, please share the link to that filed bug here) – ManmeetP Dec 07 '17 at 05:45
  • @mco, I hope your error scenario is resolved. Did you check on the above issuetracker link? – ManmeetP Dec 27 '17 at 05:11
  • how do handle request when first opening full app? onActivityResult? – fish40 Oct 07 '20 at 16:57