5

hello I am working on my own launcher that has a button that says "Google Play" what I want it to do is when the user clicks this button it takes them to the google play store home page NOT to a specific app page

heres my code:

  /** Called when the user clicks the play button */
    public void play(View view) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setComponent(new ComponentName("com.android.vending","what goes here??"));
        intent.putExtra("grace", "Hi");
        startActivity(intent);


    }

Thanks way in advance

Regards

Chris

6 Answers 6

9

Some other people have got the same problem: How to click on Android Button then go to google play apps

public void play(View view) {
  Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.theopen.android"));
  startActivity(intent);
}

Code idea from the answer from user "MAC".

4
  • that works but it says item not found what am i doing wrong?? Commented Feb 23, 2014 at 19:54
  • @ChrisDeBrodie1335 You need to replace the string in url: "com.theopen.android" for your concrete package URL. So for instance in my case, i have: package com.sbm.bc.smartbooksmobile; So I need to replace for: "com.sbm.bc.smartbooksmobile"
    – Sold Out
    Commented Jan 26, 2017 at 17:12
  • Does not work with API <= 17 .. Throws Exception "android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.sbm.bc.smartbooksmobile }" On API >= 21 it works fine. Did not try inbetween.
    – Sold Out
    Commented Jan 26, 2017 at 17:23
  • My other comment in this thread should be: Does not work with Emulators without GoogleApi included ! It throws Exception "android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.sbm.bc.smartbooksmobile }" On API = 21 with GoogleApi it works fine.
    – Sold Out
    Commented Jan 26, 2017 at 17:37
6
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.vending");
startActivity(launchIntent);
3
  • That gave me a crash when I tried it any other advice? Commented Feb 23, 2014 at 19:47
  • just get a try, it work for me, use com.android.vending as edited
    – Smile2Life
    Commented Feb 23, 2014 at 19:59
  • You forgot to tell, that you need to replace the string in url: "com.theopen.android" for your concrete package URL. So for instance in my case, i have: package com.sbm.bc.smartbooksmobile; So I need to put "com.sbm.bc.smartbooksmobile" as trailing URL string
    – Sold Out
    Commented Jan 26, 2017 at 17:10
3
Button btn2 = (Button) findViewById(R.id.danhgia);
btn2.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.ucnon.truyen"));
        startActivity(intent);
    }
});
2

Did you try entering an empty query instead of a package name? I must say I haven't tried it myself either

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=")));
1

You can use the following code

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.vending");
startActivity(launchIntent);
0

use this Code button or nav item or any clickable action

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=yourpackegName")); /// here "yourpackegName" from your app packeg Name 
        startActivity(intent);

Not the answer you're looking for? Browse other questions tagged or ask your own question.