Search code examples
javaandroidnavigationgoogle-play

Start Play Store app in Android using navigation component


I have an Android application with a button to find other games on Play Store. This button should open the Google Play Store application. I have a working version which uses the startActivity() function and Intent flags, just as mentioned in this official doc.

Intent intent = new Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse("https://play.google.com/store/apps?someapp")
                    .setPackage("com.android.vending");
this.startActivity(intent)

Is this possible to achieve using Navigation Components instead? I have tried implementing a Navigation Deep Link and to set the equivalent of intent actions and data like so:

<activity
    android:id="@+id/playstore_activity">
    <deeplink
         app:uri="https://play.google.com/store/apps?someapp"
         app:action="android.intent.action.ACTION_VIEW"
         app:targetPackage="com.android.vending"/>
</activity>

But I am getting an ActivityNotFoundException: No activity found to handle Intent error. What am I doing wrong? I am unable to find any further documentation of this.


Solution

  • I figured it out in the end:

      <activity
          android:id="@+id/playstore"
          android:label="Travel to PlayStore"
          app:action="android.intent.action.VIEW"
          app:data="@string/playstore_path"
          app:targetPackage="com.android.vending"
          />