Skip to content

Commit 0a660a3

Browse files
Merge pull request #144 from yogeshchoudhary-gts/hotfix/improvement
Use Picker Option added
2 parents 626f770 + aaac371 commit 0a660a3

File tree

7 files changed

+49
-11
lines changed

7 files changed

+49
-11
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88

99
dependencies {
1010

11-
classpath 'com.android.tools.build:gradle:3.2.0'
11+
classpath 'com.android.tools.build:gradle:4.2.1'
1212
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line
1313
}
1414
}
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Sep 26 15:59:33 AMT 2018
1+
#Thu Jul 22 17:41:01 IST 2021
22
distributionBase=GRADLE_USER_HOME
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
34
distributionPath=wrapper/dists
4-
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
6+
zipStoreBase=GRADLE_USER_HOME

library/src/main/AndroidManifest.xml

+2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
1010

11+
1112
<application
1213
android:configChanges="orientation"
1314
android:label="@string/app_name"
15+
android:requestLegacyExternalStorage="true"
1416
android:screenOrientation="portrait">
1517

1618
<provider

library/src/main/java/com/vansuita/pickimage/bundle/PickSetup.java

+11
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class PickSetup implements Serializable {
5454

5555
private String galleryChooserTitle = "";
5656
private String cameraChooserTitle = "";
57+
private boolean useChooser = true;
5758

5859
private boolean isCameraToPictures;
5960

@@ -82,6 +83,15 @@ public PickSetup setCancelText(String text) {
8283
return this;
8384
}
8485

86+
public boolean isUseChooser() {
87+
return useChooser;
88+
}
89+
90+
public PickSetup setUseChooser(boolean useChooser) {
91+
this.useChooser = useChooser;
92+
return this;
93+
}
94+
8595
public String getTitle() {
8696
return title;
8797
}
@@ -330,6 +340,7 @@ public PickSetup() {
330340
.setProgressText("Loading...")
331341
.setButtonOrientation(LinearLayout.VERTICAL)
332342
.setCameraIcon(R.drawable.camera)
343+
.setUseChooser(false)
333344
.setSystemDialog(false)
334345
.setCameraToPictures(true)
335346
.setGalleryIcon(R.drawable.gallery)

library/src/main/java/com/vansuita/pickimage/dialog/PickImageDialog.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Intent;
55
import android.content.pm.PackageManager;
66
import android.os.Bundle;
7+
import android.util.Log;
78

89
import com.vansuita.pickimage.bundle.PickSetup;
910
import com.vansuita.pickimage.keep.Keep;
@@ -87,10 +88,10 @@ public PickImageDialog setOnPickCancel(IPickCancel onPickCancel)
8788
return (PickImageDialog) super.setOnPickCancel(onPickCancel);
8889
}
8990

90-
9191
@Override
9292
public void onActivityResult(int requestCode, int resultCode, Intent data) {
9393
super.onActivityResult(requestCode, resultCode, data);
94+
Log.d("onActivityResult","requestCode => "+requestCode +"; Result Code => "+resultCode);
9495
if (requestCode == IntentResolver.REQUESTER) {
9596
if (resultCode == RESULT_OK) {
9697
//Show progress

library/src/main/java/com/vansuita/pickimage/keep/Keep.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Keep {
1515
private static final String ASKED_FOR_PERMISSION = "ASKED_FOR_PERMISSION";
1616

1717
Keep(Context context) {
18-
this.pref = context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE);
18+
this.pref = context.getSharedPreferences("testing", Context.MODE_PRIVATE);
1919
}
2020

2121
public static Keep with(Context context) {

library/src/main/java/com/vansuita/pickimage/resolver/IntentResolver.java

+29-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import androidx.core.content.FileProvider;
3434
import androidx.fragment.app.Fragment;
3535

36+
import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION;
37+
import static android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
38+
3639
/**
3740
* Created by jrvansuita build 07/02/17.
3841
*/
@@ -87,6 +90,8 @@ private Intent getCameraIntent() {
8790
} else {
8891
cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
8992
}
93+
cameraIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
94+
cameraIntent.addFlags(FLAG_GRANT_WRITE_URI_PERMISSION);
9095
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraUriForProvider());
9196

9297
applyProviderPermission();
@@ -97,9 +102,16 @@ private Intent getCameraIntent() {
97102

98103
public void launchCamera(Fragment listener) {
99104

105+
100106
cameraFile().delete();
107+
saveFile = null;
108+
109+
101110

102-
Intent chooser = Intent.createChooser(getCameraIntent(), setup.getCameraChooserTitle());
111+
Intent chooser = getCameraIntent();
112+
if (setup.isUseChooser()){
113+
chooser = Intent.createChooser(chooser, setup.getCameraChooserTitle());
114+
}
103115
listener.startActivityForResult(chooser, REQUESTER);
104116
}
105117

@@ -110,7 +122,7 @@ private void applyProviderPermission() {
110122
List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
111123
for (ResolveInfo resolveInfo : resInfoList) {
112124
String packageName = resolveInfo.activityInfo.packageName;
113-
activity.grantUriPermission(packageName, cameraUriForProvider(), Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
125+
activity.grantUriPermission(packageName, cameraUriForProvider(), FLAG_GRANT_WRITE_URI_PERMISSION | FLAG_GRANT_READ_URI_PERMISSION);
114126
}
115127
}
116128

@@ -138,7 +150,9 @@ private File cameraFile() {
138150
}
139151

140152
// File directory = new File(activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES),"teste");
141-
directory.mkdirs();
153+
if (!directory.exists())
154+
directory.mkdirs();
155+
142156
saveFile = new File(directory, fileName);
143157
Log.i("File-PickImage", saveFile.getAbsolutePath());
144158

@@ -167,7 +181,14 @@ private Uri cameraUriForProvider() {
167181

168182
private Intent getGalleryIntent() {
169183
if (galleryIntent == null) {
170-
galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
184+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
185+
galleryIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
186+
galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
187+
galleryIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
188+
galleryIntent.addFlags(FLAG_GRANT_WRITE_URI_PERMISSION);
189+
}else{
190+
galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
191+
}
171192
if (setup.isVideo()) {
172193
galleryIntent.setType(activity.getString(R.string.video_content_type));
173194
} else {
@@ -179,7 +200,10 @@ private Intent getGalleryIntent() {
179200
}
180201

181202
public void launchGallery(Fragment listener,String title) {
182-
Intent intent = Intent.createChooser(getGalleryIntent(),title);
203+
Intent intent = getGalleryIntent();
204+
if (setup.isUseChooser()){
205+
intent = Intent.createChooser(intent, title);
206+
}
183207
try {
184208
listener.startActivityForResult(intent, REQUESTER);
185209
} catch (ActivityNotFoundException e) {

0 commit comments

Comments
 (0)