我正在寻找Java样板,用于从我的即时应用程序调用我的可安装应用程序。我在GitHub的https://github.com/googlesamples/android-instant-apps上找到了一些用Kotlin编写的代码,我正在尝试翻译并开始工作。我很惊讶什么地方没有提供这个Java,至少我还没有找到它。目前,我只是在Goggle Play上提供了一个指向我的可安装应用程序的链接,用户一开始就应该从这个链接下载即时应用程序。比在即时应用程序上打开一个漂亮的窗口要粗糙一点。
发布于 2019-09-05 04:44:53
以下是Java代码的两个命令,它们将在即时应用程序中打开一个窗口,指向Google Play上的可安装应用程序。我从Kotlin代码翻译过来的,我在这里找到了GitHub上的示例应用程序:https://github.com/googlesamples/android-instant-apps。
带有Java错误的Kotlin原始版本:
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.Button
import com.google.android.gms.instantapps.InstantApps

Java:
import com.google.android.gms.instantapps.InstantApps;
import android.content.Intent;
import android.net.Uri;
Intent postInstallIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://install-api.instantappsample.com/")).
addCategory(Intent.CATEGORY_BROWSABLE);
InstantApps.showInstallPrompt((Activity)getContext(),//'this' if calling from main
postInstallIntent,7,"InstallApiActivity");或
Intent postInstallIntent = new Intent(Intent.ACTION_MAIN,
Uri.parse("https://your.package.name/")).
addCategory(Intent.CATEGORY_DEFAULT);
InstantApps.showInstallPrompt((Activity)getContext(),postInstallIntent,7,null);不同的参数对此有效,尽管第二个参数更接近我在https://developer.android.com/topic/google-play-instant/getting-started/instant-enabled-app-bundle#java中发现的内容。奖励代码,Java即时应用标志:
boolean isInstantApp = InstantApps.getPackageManagerCompat(getContext()).isInstantApp();我有提过我有多讨厌Kotlin吗?注意:如果Google Play在用户设备上被禁用,这将使应用程序崩溃。我费了好大劲才发现这一点,在禁用Google Play测试我的应用程序页面在浏览器上的外观后,我花了几个小时试图解决“找不到活动”的错误。如果你不先禁用Google Play应用程序,在手机浏览器上搜索“Google Play”会自动弹出该应用程序,至少对我来说是这样。
https://stackoverflow.com/questions/57778716
复制相似问题