File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/home/repository Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -43,19 +43,28 @@ public HomeRepository(Context context) {
4343 */
4444 public Intent getPlayStoreIntent () {
4545 String playStoreUrl = "https://play.google.com/store/apps/details?id=" + BuildConfig .APPLICATION_ID ;
46- Intent intent = new Intent (Intent .ACTION_VIEW , Uri .parse (playStoreUrl ));
47- intent .setPackage ("com.android.vending" );
48- return intent ;
46+ return buildPlayStoreIntent (playStoreUrl );
4947 }
5048
5149 /**
5250 * Returns an Intent that opens the Google Play Store page for the provided package.
5351 */
5452 public Intent getAppPlayStoreIntent (String packageName ) {
5553 String url = "https://play.google.com/store/apps/details?id=" + packageName ;
56- Intent intent = new Intent (Intent .ACTION_VIEW , Uri .parse (url ));
57- intent .setPackage ("com.android.vending" );
58- return intent ;
54+ return buildPlayStoreIntent (url );
55+ }
56+
57+ /**
58+ * Builds an intent that opens a Play Store url if the Google Play app is
59+ * installed, otherwise falls back to a generic ACTION_VIEW intent.
60+ */
61+ private Intent buildPlayStoreIntent (String url ) {
62+ Intent playStoreIntent = new Intent (Intent .ACTION_VIEW , Uri .parse (url ));
63+ playStoreIntent .setPackage ("com.android.vending" );
64+ if (playStoreIntent .resolveActivity (context .getPackageManager ()) != null ) {
65+ return playStoreIntent ;
66+ }
67+ return new Intent (Intent .ACTION_VIEW , Uri .parse (url ));
5968 }
6069
6170 /**
You can’t perform that action at this time.
0 commit comments