将用户从Android应用重定向到Play store

将用户从Android应用重定向到Play store,android,google-play,Android,Google Play,朋友们好,我正在开发一个应用程序,我需要将用户重定向到我的应用程序中的play store,我搜索了很多,但没有成功。。代码如下 Button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v_arg) { try { Intent viewIntent =

朋友们好,我正在开发一个应用程序,我需要将用户重定向到我的应用程序中的play store,我搜索了很多,但没有成功。。代码如下

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();
            }
        }
    });

从url中删除斜杠。在包名称后添加了额外的斜杠

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都应该是

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


您只需要从url中删除字符
“/”

也将如此

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();
        }
    }
});

更复杂的方式:

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)));
}

你的代码似乎还可以。您是否有任何错误?如果在不同的
构建类型中使用
applicationIdSuffix
请小心,否则在非生产构建中构建时会失败,因为packageName将与您在Google Play store上拥有的不同。一个包可能类似于
com.youpackage.debug
,而发行版可能类似于
com.youpackage