Skip to content

Commit 760fcab

Browse files
author
Honza Rychnovský
committedOct 31, 2018
Add openAppPlayStoreSubscriptions method to IntentUtils
1 parent 53cc426 commit 760fcab

File tree

5 files changed

+85
-62
lines changed

5 files changed

+85
-62
lines changed
 

‎app/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ dependencies {
2525
exclude group: 'com.android.support', module: 'support-annotations'
2626
})
2727
implementation 'com.android.support:appcompat-v7:27.1.1'
28-
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
2928
implementation 'com.google.code.gson:gson:2.8.2'
3029
testImplementation 'junit:junit:4.12'
3130
implementation project(path: ':library')

‎app/src/main/java/com/honzar/adtutils/sampleApp/MainActivity.java

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package com.honzar.adtutils.sampleApp;
22

3-
import android.content.Intent;
43
import android.os.Bundle;
54
import android.support.v7.app.AppCompatActivity;
65

76
import com.honzar.adtutils.library.IntentUtils;
87

9-
import java.io.File;
10-
import java.io.IOException;
11-
128
public class MainActivity extends AppCompatActivity {
139

1410
@Override
@@ -49,26 +45,31 @@ protected void onCreate(Bundle savedInstanceState) {
4945
//
5046
// //IntentUtils.openFilePickerComponent(MainActivity.this,"video/*", "TEST TITLE", 101);
5147

52-
file = new File(getExternalFilesDir(null), "image.mp4");
53-
try {
54-
file.createNewFile();
55-
} catch (IOException e) {
56-
e.printStackTrace();
57-
}
58-
59-
IntentUtils.openCameraAppForPhoto(MainActivity.this, 2209, false, file, true);
60-
}
61-
File file;
48+
// file = new File(getExternalFilesDir(null), "image.mp4");
49+
// try {
50+
// file.createNewFile();
51+
// } catch (IOException e) {
52+
// e.printStackTrace();
53+
// }
54+
//
55+
// IntentUtils.openCameraAppForPhoto(MainActivity.this, 2209, false, file, true);
56+
// }
57+
// File file;
6258

63-
@Override
64-
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
65-
super.onActivityResult(requestCode, resultCode, data);
6659

67-
if (requestCode == 2209) {
60+
IntentUtils.openAppPlayStoreSubscriptions(MainActivity.this);
6861

69-
if (resultCode == RESULT_OK) {
70-
String filePath = file.getAbsolutePath();
71-
}
72-
}
7362
}
63+
64+
// @Override
65+
// protected void onActivityResult(int requestCode, int resultCode, Intent data) {
66+
// super.onActivityResult(requestCode, resultCode, data);
67+
//
68+
// if (requestCode == 2209) {
69+
//
70+
// if (resultCode == RESULT_OK) {
71+
// String filePath = file.getAbsolutePath();
72+
// }
73+
// }
74+
// }
7475
}
+3-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
43
xmlns:tools="http://schemas.android.com/tools"
54
android:layout_width="match_parent"
65
android:layout_height="match_parent"
@@ -9,10 +8,6 @@
98
<TextView
109
android:layout_width="wrap_content"
1110
android:layout_height="wrap_content"
12-
android:text="Hello World!"
13-
app:layout_constraintBottom_toBottomOf="parent"
14-
app:layout_constraintLeft_toLeftOf="parent"
15-
app:layout_constraintRight_toRightOf="parent"
16-
app:layout_constraintTop_toTopOf="parent" />
11+
android:text="Hello World!" />
1712

18-
</android.support.constraint.ConstraintLayout>
13+
</FrameLayout>

‎library/src/main/java/com/honzar/adtutils/library/DeviceUtils.java

-31
Original file line numberDiff line numberDiff line change
@@ -301,37 +301,6 @@ public static boolean isSmartphone(Context context)
301301
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) < Configuration.SCREENLAYOUT_SIZE_LARGE;
302302
}
303303

304-
/**
305-
* Opens Google Play Store page in Play Store app if installed or in browser.
306-
*
307-
* @param context
308-
* @param packageName package name of app developer wants to open on Play Store
309-
*
310-
* @return true/false
311-
*/
312-
public static boolean openAppPlayStore(Context context, String packageName)
313-
{
314-
if (checkNull(context) || checkNull(packageName) || packageName.isEmpty())
315-
return false;
316-
317-
Uri rateUri = Uri.parse("market://details?id=" + packageName);
318-
Intent goToMarket = new Intent(Intent.ACTION_VIEW, rateUri);
319-
320-
// To count with Play market backstack, After pressing back button,
321-
// to taken back to our application, we need to add following flags to intent.
322-
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
323-
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
324-
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
325-
326-
try {
327-
context.startActivity(goToMarket);
328-
} catch (ActivityNotFoundException e) {
329-
Uri storeUri = Uri.parse("http://play.google.com/store/apps/details?id=" + packageName);
330-
context.startActivity(new Intent(Intent.ACTION_VIEW, storeUri));
331-
}
332-
return true;
333-
}
334-
335304
//
336305
// SDK VERSIONS
337306
//

‎library/src/main/java/com/honzar/adtutils/library/IntentUtils.java

+59
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,66 @@ public static boolean openImageInGalleryApp(Context context, File file)
450450
return openImageInGalleryApp(context, Uri.parse("file://" + file.getAbsolutePath()));
451451
}
452452

453+
/**
454+
* Opens Google Play Store page in Play Store app if installed or in browser.
455+
*
456+
* @param context
457+
* @param packageName package name of app developer wants to open on Play Store
458+
*
459+
* @return true/false
460+
*/
461+
public static boolean openAppPlayStore(Context context, String packageName)
462+
{
463+
if (checkNull(context) || checkNull(packageName) || packageName.isEmpty())
464+
return false;
465+
466+
Uri rateUri = Uri.parse("market://details?id=" + packageName);
467+
Intent goToMarket = new Intent(Intent.ACTION_VIEW, rateUri);
468+
469+
// To count with Play market backstack, After pressing back button,
470+
// to taken back to our application, we need to add following flags to intent.
471+
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
472+
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
473+
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
474+
475+
try {
476+
context.startActivity(goToMarket);
477+
} catch (ActivityNotFoundException e) {
478+
Uri storeUri = Uri.parse("http://play.google.com/store/apps/details?id=" + packageName);
479+
context.startActivity(new Intent(Intent.ACTION_VIEW, storeUri));
480+
}
481+
return true;
482+
}
453483

484+
/**
485+
* Opens Google Play Store on Subscription page in Play Store app if installed or in browser.
486+
*
487+
* @param context
488+
*
489+
* @return true/false
490+
*/
491+
public static boolean openAppPlayStoreSubscriptions(Context context)
492+
{
493+
if (checkNull(context))
494+
return false;
495+
496+
Uri rateUri = Uri.parse("https://play.google.com/store/account/subscriptions");
497+
Intent goToMarket = new Intent(Intent.ACTION_VIEW, rateUri);
498+
499+
// To count with Play market backstack, After pressing back button,
500+
// to taken back to our application, we need to add following flags to intent.
501+
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
502+
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
503+
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
504+
505+
try {
506+
context.startActivity(goToMarket);
507+
} catch (ActivityNotFoundException e) {
508+
Uri storeUri = Uri.parse("https://play.google.com/store/account/subscriptions");
509+
context.startActivity(new Intent(Intent.ACTION_VIEW, storeUri));
510+
}
511+
return true;
512+
}
454513

455514
//
456515
// TURN DEVICE ACCESSORY ON

0 commit comments

Comments
 (0)
Please sign in to comment.