3

I copied the source code of this popular question on how to make a “Rate This App”-link in Google Play store app on the phone .

On my Android Studio (version 3.1.2) with an Emulator this works perfectly. However, on my Samsung Galaxy A5 (2017) (Android 8.0) device the link always opens the Google Play app but shows me the start page instead of the app page.

I wonder why they are acting differently and what can I do to make it work on my device, too. I wonder if it is some setting I have on my device that prevents the deep link?

My code:

Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);       
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
    Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
    Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
try {
  startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
  startActivity(new Intent(Intent.ACTION_VIEW,
      Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
}
John Threepwood
  • 15,593
  • 27
  • 93
  • 149
  • 1
    post your code please... – Masoom Badi May 13 '18 at 07:18
  • 1
    Try removing all of those excessive flags. – dominicoder May 13 '18 at 07:41
  • @dominicoder Yes, I tried it without adding these flags. The same result: On the emulator everything works, on my device not. I begin to wonder if it is some setting I have on my device that prevents the deep link? – John Threepwood May 13 '18 at 11:14
  • From where you are trying to do this deep linking? From another application or some browser? – Jitesh Mohite May 17 '18 at 03:37
  • Please post code of menifest – Jitesh Mohite May 17 '18 at 03:46
  • 1
    Please let me know if this open WhatsApp page inside play store( startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + "com.whatsapp")));). Use same device where you are facing problem – Jitesh Mohite May 17 '18 at 07:39
  • I tried your code in my device (Nexus 5X with Android 8.1) and "works" fine. I said "works" because with all flags you put the Play Store activity is opened when I press back button, not when the code is executed. I tried with com.whatsapp like @jiteshmohite said, and removing all flags works ultra great. So I'm thinking with a problem of your device. Have you the change to test your code in other real devices? Aniway, I would delete all flags because are useles, even harmful. – Marc Estrada May 17 '18 at 11:29
  • Please check my answer and let me know if it's missing something – Leo supports Monica Cellio May 19 '18 at 17:29

3 Answers3

3

I am 100% sure that the problem is in your phone, and not in your code.

My phone did not have this problem and I was able to reproduce it by changing one of the SQLite databases that ship with Google Play Services. Below I explain how did it on my phone, and also how the issue might be fixed in your phone.

How to reproduce the bug with a phone that didn't have it

First, I made sure to have your root access setting set to "ADB only" or "ADB and Apps" in my phone's Developer Settings. Then i ran adb root and adb shell to have access to the device with a command line`

Once inside, I ran su to become root.

Then I went to directory /data/data/com.google.android.gsf/databases, where there was the database gservices.db, which I wanted to change.

To read and write the database it, I ran sqlite3 gservices.db, and this database has table named overrides. To see the content of this table, I ran the command SELECT * FROM overrides;, paying attention not to forget the final semi-colon.

In my case the table was completely empty, but I bet that in your phone there is something there, because to reproduce the bug on your phone I ran this command (again remember the semi-colon):

INSERT INTO overrides VALUES ("finsky.launch_urls_enabled", "false");

To exit sqlite3 I entered .exit, and then I rebooted my phone.

Results

After rebooting, I tried your code and voila, it went Google Play's home page instead of the app's page. I even went to Amaze File Manager's user settings, from which you can rate the app, and the result was the same, it went to the homepage.

How to remove your bug (speculative)

You can try following the steps above, replacing the INSERT SQLite statement, with this one:

UPDATE overrides SET value="false" WHERE name="finsky.launch_urls_enabled"

  • Thank you for your investigation. The misbehavior on my device just disappeared the other day. Now the exact same app shows the app page in the Play store. So it must have been some temporarily wrong configuration on my device. It might have been the issue you could find (but I did not test it). Anyway, your answer comes to the closest I saw, I will reward you the bounty. – John Threepwood May 21 '18 at 15:34
  • Thanks! My phone still shows the same behavior for the app I made based on your question and for Amazing File Explorer, but yesterday I came accross another app which works properly on the same phone. I will keep looking when I have some time, I might have a proper answer for you after all. – Leo supports Monica Cellio May 21 '18 at 17:15
0

Apparently, getPackageName() is not returning the value you need. What context you get it from depends on where is your code running.

Without knowing what's the context, I could suggest using this instead:

getApplicationContext().getPackageName()
JP de la Torre
  • 1,593
  • 18
  • 20
-1

Try this

  Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    // To count with Play market backstack, After pressing back button, 
    // to taken back to our application, we need to add following flags to intent. 
    goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
                    Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    try {
        startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
    }