Android Instant App:showInstallPrompt的postInstallIntent什么都不做? [英] Android Instant App: showInstallPrompt's postInstallIntent does nothing?

查看:109
本文介绍了Android Instant App:showInstallPrompt的postInstallIntent什么都不做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前将Play商店中的应用配置为在意图过滤器中处理https://www.example.com/hello/以启动活动,并且应该在应用安装完成后启动showInstallPrompt(...)来启动活动.

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(...)文档:

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

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.

我尝试这样做:

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

还有这个

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

还有这个

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

它带给了我Play商店,但安装完成后,它们都没有自动启动该应用.

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

推荐答案

请查看:
https://github.com/googlesamples/android-instant- apps/tree/master/install-api

> https://github.com/googlesamples/android-instant-apps/blob/master/install-api/features/install/src/main/java/com/instantappsamples/feature/install/InstallApiActivity.kt

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

  • 该示例应用程序演示了如何使用安装API . API触发了在设备上安装应用程序的意图.
  • 该调用还接受Intent,该Intent在安装完成后触发.
  • 该示例还显示了实现showInstallPrompt方法和postInstallIntent的正确结构.
  • 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.

请参考示例代码段:

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

这篇关于Android Instant App:showInstallPrompt的postInstallIntent什么都不做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆