Sto*_*nek 5 android google-play android-instant-apps
如何在Wisher,Buzzfeed,Vimeo等弹出窗口中打开Google Play?
我查看了Google文档,但只有Google Play应用(market://)或浏览器(http://)开放.
我想在我的即时应用程序内打开,以便在屏幕上安装完整的应用程序.
TL; DR:
InstantApps.showInstallPrompt(activity,
postInstallIntent,
Constants.INSTALL_INSTANT_APP_REQUEST_CODE,
referrerString);
Run Code Online (Sandbox Code Playgroud)
在Vimeo,我们使用Branch进行网络 - >移动应用安装以及我们的即时应用 - >移动应用安装(因为它提供了一些额外的指标,让我们可以更好地比较引用).
如果您对使用Branch感兴趣,可以在此处找到安装提示的文档.用法如下:
if (Branch.isInstantApp(this)) {
myFullAppInstallButton.setVisibility(View.VISIBLE);
myFullAppInstallButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
BranchUniversalObject branchUniversalObject = new BranchUniversalObject()
.setCanonicalIdentifier("item/12345")
.setTitle("My Content Title")
.setContentDescription("My Content Description")
.setContentImageUrl("https://example.com/mycontent-12345.png")
.setContentMetadata(new ContentMetadata()
.addCustomMetadata("property1", "blue")
.addCustomMetadata("property2", "red"));
Branch.showInstallPrompt(myActivity, activity_ret_code, branchUniversalObject);
}
});
} else {
myFullAppInstallButton.setVisibility(View.GONE);
}
Run Code Online (Sandbox Code Playgroud)
分公司的实现最终通过电话向对方的回答中提到的API 在这里.
看起来像:
public static boolean showInstallPrompt(Activity activity,
Intent postInstallIntent,
int requestCode,
String referrer)
Run Code Online (Sandbox Code Playgroud)
显示一个允许用户安装当前即时应用程序的对话框.如果当前正在运行的进程是已安装的应用程序,则此方法为无操作.您必须提供安装后意图,系统在安装完成后使用该意图启动应用程序.
您可以在此处找到示例用法.看起来如下:
class InstallApiActivity : AppCompatActivity() {
/**
* Intent to launch after the app has been installed.
*/
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)
}
}
}
}
companion object {
private val REFERRER = "InstallApiActivity"
private val REQUEST_CODE = 7
}
}
Run Code Online (Sandbox Code Playgroud)
它不推荐使用,因为它已被弃用,但您可以在技术上使用以下代码显示对话框:
InstantApps.showInstallPrompt(activity, Constants.INSTALL_INSTANT_APP_REQUEST_CODE, null);
Run Code Online (Sandbox Code Playgroud)
另见:https://stackoverflow.com/a/47666873/1759443