如何点击Android按钮,然后进入google play应用程序
我想知道如何使android按钮可以点击并将用户重定向到google play 示例:我想将用户发送到android应用程序(https://play.google.com/store/apps/details?id=com.theopen.android)用户单击“我的活动”中的按钮后 如何做到这一点 问候,如何点击Android按钮,然后进入google play应用程序,android,Android,我想知道如何使android按钮可以点击并将用户重定向到google play 示例:我想将用户发送到android应用程序(https://play.google.com/store/apps/details?id=com.theopen.android)用户单击“我的活动”中的按钮后 如何做到这一点 问候, intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.theopen.android"));
intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.theopen.android"));
startActivity(intent);
这将在Play store(android market)中打开您的应用程序。要重定向到google Play,我们需要检查手机是否已经有Play store应用程序,如果没有,则应在浏览器中打开google Play
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.android.app"));
try{
startActivity(intent);
}
catch(Exception e){ intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.android.app"));
}
看看我所做的,即使没有应用程序(比如GooglePlay)来实现第一个目的,它也能工作。在这种情况下,会有另一次尝试在web浏览器中打开GooglePlay-至少应有默认值:
mOkButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.sbm.bc.smartbooksmobile")); // Open precisely @link SmartBooks
boolean tryAgain = false; // Flag to denote that normal attempt to launch GooglePlay update failed
try
{
startActivity(intent);
}
catch(Exception e)
{
tryAgain = true;
}
if (!tryAgain) return;
// Try to launch GooglePlay with SB in browser !
try
{
intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.sbm.bc.smartbooksmobile"));
startActivity(intent);
}
catch (Exception e)
{
mEmailView.setError("Unable to run app update automatically. Please run it from GooglePlay manualy.");
mEmailView.requestFocus(View.FOCUS_UP);
}
// No need to exit the app, as it already exits
//finishAffinity(); // this requires API level > 16
//finish();
//System.exit(0);
}
});
我认为这应该被标记为正确答案。您忘记告诉我,您需要替换url中的字符串:“com.theopen.android”作为您的具体包url。例如,在我的例子中,我有:package com.sbm.bc.smartbooksmobile;所以我需要把“com.sbm.bc.smartbooksmobile”作为后续URL字符串,这有助于在预先准备好的WebView中打开应用程序内部。但问题是关于去谷歌Play应用程序。(可能是为了更新此应用程序,或推荐其他应用程序)。
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("package name here");
startActivity(launchIntent);
mOkButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.sbm.bc.smartbooksmobile")); // Open precisely @link SmartBooks
boolean tryAgain = false; // Flag to denote that normal attempt to launch GooglePlay update failed
try
{
startActivity(intent);
}
catch(Exception e)
{
tryAgain = true;
}
if (!tryAgain) return;
// Try to launch GooglePlay with SB in browser !
try
{
intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.sbm.bc.smartbooksmobile"));
startActivity(intent);
}
catch (Exception e)
{
mEmailView.setError("Unable to run app update automatically. Please run it from GooglePlay manualy.");
mEmailView.requestFocus(View.FOCUS_UP);
}
// No need to exit the app, as it already exits
//finishAffinity(); // this requires API level > 16
//finish();
//System.exit(0);
}
});