打开 Google 在弹出窗口中播放(如 Vimeo、Wisher、Buzzfeed)- 即时应用
Opening Google Play in popup (like Vimeo, Wisher, Buzzfeed) - Instant App
如何打开 Google 在 Wisher、Buzzfeed、Vimeo 等弹出窗口中播放?
我看了Google documentation,但只有通过Google Play 应用程序(market://
)或浏览器(http://
)打开的问题。
我想在我的免安装应用程序中打开,以便像在屏幕上一样安装完整的应用程序。
我想你正在寻找 showInstallPrompt。
长话短说:
InstantApps.showInstallPrompt(activity,
postInstallIntent,
Constants.INSTALL_INSTANT_APP_REQUEST_CODE,
referrerString);
在 Vimeo,我们将 Branch 用于我们的网络 -> 移动应用程序安装以及我们的即时应用程序 -> 移动应用程序安装(因为它提供了一些额外的指标并让我们更好地比较引荐来源网址)。
如果您对使用 Branch 感兴趣,可以找到安装提示的文档 here。用法如下:
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);
}
Branch 的实现最终调用了另一个答案 here 中提到的 API。
看起来像:
public static boolean showInstallPrompt(Activity activity,
Intent postInstallIntent,
int requestCode,
String referrer)
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.
您可以找到一个示例用法 here。看起来如下所示:
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
}
}
不推荐,因为它已被弃用,但从技术上讲,您可以使用以下代码显示对话框:
InstantApps.showInstallPrompt(activity, Constants.INSTALL_INSTANT_APP_REQUEST_CODE, null);
另请参阅:
如何打开 Google 在 Wisher、Buzzfeed、Vimeo 等弹出窗口中播放?
我看了Google documentation,但只有通过Google Play 应用程序(market://
)或浏览器(http://
)打开的问题。
我想在我的免安装应用程序中打开,以便像在屏幕上一样安装完整的应用程序。
我想你正在寻找 showInstallPrompt。
长话短说:
InstantApps.showInstallPrompt(activity,
postInstallIntent,
Constants.INSTALL_INSTANT_APP_REQUEST_CODE,
referrerString);
在 Vimeo,我们将 Branch 用于我们的网络 -> 移动应用程序安装以及我们的即时应用程序 -> 移动应用程序安装(因为它提供了一些额外的指标并让我们更好地比较引荐来源网址)。
如果您对使用 Branch 感兴趣,可以找到安装提示的文档 here。用法如下:
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);
}
Branch 的实现最终调用了另一个答案 here 中提到的 API。
看起来像:
public static boolean showInstallPrompt(Activity activity,
Intent postInstallIntent,
int requestCode,
String referrer)
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.
您可以找到一个示例用法 here。看起来如下所示:
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
}
}
不推荐,因为它已被弃用,但从技术上讲,您可以使用以下代码显示对话框:
InstantApps.showInstallPrompt(activity, Constants.INSTALL_INSTANT_APP_REQUEST_CODE, null);
另请参阅: