你好朋友我正在开发一个应用程序,我有一个要求从我的应用程序重定向用户到Play商店,我搜索了很多但没有成功..代码在下面
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();
}
}
});
答案 0 :(得分:21)
更复杂的方式:
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)));
}
答案 1 :(得分:9)
从网址中删除斜杠。您在包名后添加了额外的斜杠。
https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/
应该是
https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla
两个人都应该
Uri.parse("https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla")); // Removed slash
和
Uri.parse("market://details?id=com.adeebhat.rabbitsvilla")); // Removed slash
答案 2 :(得分:8)
您只需要从网址
中删除字符"/"
即可
所以
https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/
到
https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla
最后
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();
}
}
});