Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect User to Play store From Android App

Hello Friends i am developing an app , i had an requirement to redirect user to play store from my app , i searched a lot but no success .. code is below

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();
            }
        }
    });
like image 945
ADIL BHAT Avatar asked Apr 24 '14 08:04

ADIL BHAT


2 Answers

More sophisticated way:

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)));
}
like image 191
Tushar Monirul Avatar answered Oct 20 '22 19:10

Tushar Monirul


You just need to remove character "/" from the url

So will be

https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/

to

https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla

So finally

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();
        }
    }
});
like image 44
Piyush Avatar answered Oct 20 '22 20:10

Piyush