gpt4 book ai didi

android - 从 Android 应用程序将用户重定向到 Play 商店

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:16:25 24 4
gpt4 key购买 nike

你好 friend 我正在开发一个应用程序,我需要将用户重定向到我的应用程序中的商店,我搜索了很多但没有成功..代码如下

Button1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v_arg) {
try {
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse("https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/"));
startActivity(viewIntent);
}catch(Exception e) {
Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});

Button2.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v_arg) {
try {
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse("market://details?id=com.adeebhat.rabbitsvilla/"));
startActivity(viewIntent);
}catch(Exception e) {
Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});

最佳答案

更复杂的方式:

final String appPackageName = getPackageName(); // package name of the app
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}

关于android - 从 Android 应用程序将用户重定向到 Play 商店,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23264257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com