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) {
43
43
*/
44
44
public Intent getPlayStoreIntent () {
45
45
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 );
49
47
}
50
48
51
49
/**
52
50
* Returns an Intent that opens the Google Play Store page for the provided package.
53
51
*/
54
52
public Intent getAppPlayStoreIntent (String packageName ) {
55
53
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 ));
59
68
}
60
69
61
70
/**
You can’t perform that action at this time.
0 commit comments