我正在寻找Java样板,用于从即时应用程序中调用可安装的应用程序。我在https://github.com/googlesamples/android-instant-apps的GitHub上找到了Kotlin编码的内容,我正在尝试翻译并开始工作。我很惊讶Java并未在某处提供,至少我没有找到它。目前,我只是在Goggle Play上提供了指向我的可安装应用程序的链接,用户首先应该从该位置下载了即时应用程序。比在即时应用程序上打开漂亮的窗口要简单一些。
答案 0 :(得分:1)
以下是两个Java代码命令,这些命令将在您的即时应用中打开一个窗口,可访问您在Google Play上可安装的应用。我是从Kotlin代码翻译而成的,该代码在GitHub上的示例应用程序中位于https://github.com/googlesamples/android-instant-apps内。
Kotlin原始版出现Java错误:
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");
奖金代码,Java即时应用标志:
boolean isInstantApp = InstantApps.getPackageManagerCompat(getContext()).isInstantApp();
我有没有提起我讨厌科特林?