John Threepwood
John Threepwood

Reputation: 16143

Deep link to Google Play app shows Google Play start page instead

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

Upvotes: 3

Views: 4324

Answers (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"

Upvotes: 3

JP de la Torre
JP de la Torre

Reputation: 1761

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

Upvotes: 0

user8412632
user8412632

Reputation:

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

Upvotes: -1

Related Questions