Android即时应用:showInstallPrompt的postInstallIntent什么都不做?

时间:2017-12-01 23:52:06

标签: android android-intent android-instant-apps

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

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

showInstallPrompt(...)文档:

  

显示一个允许用户安装当前即时应用的对话框。如果当前正在运行的进程是已安装的应用程序,则此方法为无操作。您必须提供安装后意图,系统在安装完成后使用该意图启动应用程序。

postInstallIntent Docs:

  

安装即时应用程序后启动的意图。此意图必须解析为已安装的应用包中的活动,否则将无法使用。

我试过这样做:

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

它为我带来了游戏商店,但是一旦安装完成,它们都不会自动启动应用程序。

1 个答案:

答案 0 :(得分:2)

请看一下:
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

  • 此示例应用演示如何使用Install API。 API触发Intent在设备上安装应用程序。
  • 该调用还接受Intent,它在安装完成后触发。
  • 该示例还显示了与showInstallPrompt一起实施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)
            } }
    } }
相关问题