简体   繁体   English

Android Instant App:showInstallPrompt的postInstallIntent什么都不做?

[英]Android Instant App: showInstallPrompt's postInstallIntent does nothing?

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. Play商店中的应用程序当前配置为在意图过滤器中处理https://www.example.com/hello/以启动活动,并且showInstallPrompt(...)应该在安装应用程序后启动活动完了。

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

showInstallPrompt(...) Docs: showInstallPrompt(...)文档:

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: postInstallIntent文档:

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. 它为我带来了游戏商店,但是一旦安装完成,它们都不会自动启动应用程序。

Please have a look at: 请看看:
https://github.com/googlesamples/android-instant-apps/tree/master/install-api 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 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 . 此示例应用程序演示了如何使用Install API The API triggers the Intent to install the app on device. API触发Intent在设备上安装应用程序。
  • The call also accepts the Intent, which is triggered after the installation is complete. 该调用还接受Intent,它在安装完成后触发。
  • The sample also shows the correct structure to implement showInstallPrompt method along with postInstallIntent . 该示例还显示了与postInstallIntent一起实现showInstallPrompt方法的正确结构。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM