2929
3030public class EasyImagePicker {
3131
32-
33- public static final int REQUEST_TAKE_PHOTO = 1 ;
34- public static final int REQUEST_GALLERY_PHOTO = 2 ;
32+ enum FILE_TYPE {
33+ CAMERA ,GALLERY ,FILE
34+ }
35+ public static final int REQUEST_TAKE_PHOTO = 111 ;
36+ public static final int REQUEST_GALLERY_PHOTO = 222 ;
37+ public static final int REQUEST_FILE = 777 ;
3538 File mPhotoFile ;
3639 FileCompressor mCompressor ;
3740 private Activity mContext ;
@@ -53,11 +56,16 @@ public EasyImagePicker openEasyPicker() {
5356 return this ;
5457 }
5558 public EasyImagePicker openCamera () {
56- requestPermissions (true );
59+ requestPermissions (FILE_TYPE . CAMERA );
5760 return this ;
5861 }
5962 public EasyImagePicker openGallery () {
60- requestPermissions (false );
63+ requestPermissions (FILE_TYPE .GALLERY );
64+ return this ;
65+ }
66+
67+ public EasyImagePicker openFilePicker () {
68+ requestPermissions (FILE_TYPE .FILE );
6169 return this ;
6270 }
6371
@@ -71,7 +79,7 @@ public void showDialog() {
7179 btnCamera .setOnClickListener (new View .OnClickListener () {
7280 @ Override
7381 public void onClick (View v ) {
74- requestPermissions (true );
82+ requestPermissions (FILE_TYPE . CAMERA );
7583 dialog .dismiss ();
7684
7785 }
@@ -80,7 +88,7 @@ public void onClick(View v) {
8088 btnGallery .setOnClickListener (new View .OnClickListener () {
8189 @ Override
8290 public void onClick (View v ) {
83- requestPermissions (false );
91+ requestPermissions (FILE_TYPE . GALLERY );
8492 dialog .dismiss ();
8593
8694 }
@@ -99,10 +107,38 @@ public void onClick(View v) {
99107
100108 }
101109
110+
111+ private void intentFilPicker ()
112+ {
113+ Intent intent ;
114+ if (android .os .Build .MANUFACTURER .equalsIgnoreCase ("samsung" )) {
115+ intent = new Intent ("com.sec.android.app.myfiles.PICK_DATA" );
116+ intent .putExtra ("CONTENT_TYPE" , "*/*" );
117+ intent .addCategory (Intent .CATEGORY_DEFAULT );
118+ } else {
119+
120+ String [] mimeTypes =
121+ {
122+ "application/msword" , "application/vnd.openxmlformats-officedocument.wordprocessingml.document" , // .doc & .docx
123+ "application/vnd.ms-powerpoint" , "application/vnd.openxmlformats-officedocument.presentationml.presentation" , // .ppt & .pptx
124+ "application/vnd.ms-excel" , "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" , // .xls & .xlsx
125+ "text/plain" ,
126+ "application/pdf" ,
127+ "application/zip" , "application/vnd.android.package-archive" };
128+
129+ intent = new Intent (Intent .ACTION_GET_CONTENT ); // or ACTION_OPEN_DOCUMENT
130+ intent .setType ("*/*" );
131+ intent .putExtra (Intent .EXTRA_MIME_TYPES , mimeTypes );
132+ intent .addCategory (Intent .CATEGORY_OPENABLE );
133+ //intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
134+ }
135+
136+ mContext .startActivityForResult (intent ,REQUEST_FILE );
137+ }
102138 /**
103139 * Capture image from camera
104140 */
105- public void dispatchTakePictureIntent () {
141+ private void dispatchTakePictureIntent () {
106142
107143 Intent takePictureIntent = new Intent (MediaStore .ACTION_IMAGE_CAPTURE );
108144 if (takePictureIntent .resolveActivity (mContext .getPackageManager ()) != null ) {
@@ -125,7 +161,7 @@ public void dispatchTakePictureIntent() {
125161 }
126162 }
127163
128- private void requestPermissions (final boolean isCamera ) {
164+ private void requestPermissions (final FILE_TYPE type ) {
129165 Dexter .withActivity (mContext ).withPermissions (Manifest .permission .READ_EXTERNAL_STORAGE ,
130166 Manifest .permission .WRITE_EXTERNAL_STORAGE , Manifest .permission .CAMERA )
131167 .withListener (new MultiplePermissionsListener () {
@@ -134,10 +170,24 @@ public void onPermissionsChecked(MultiplePermissionsReport report) {
134170
135171 // check if all permissions are granted
136172 if (report .areAllPermissionsGranted ()) {
137- if (isCamera ) {
138- dispatchTakePictureIntent ();
139- } else {
140- dispatchGalleryIntent ();
173+
174+ switch (type )
175+ {
176+ case FILE :
177+ {
178+ intentFilPicker ();
179+ }
180+ break ;
181+ case GALLERY :
182+ {
183+ dispatchGalleryIntent ();
184+ }
185+ break ;
186+ case CAMERA :
187+ {
188+ dispatchTakePictureIntent ();
189+ }
190+ break ;
141191 }
142192 }
143193 // check for permanent denial of any permission
@@ -198,6 +248,23 @@ else if (resultCode == Activity.RESULT_CANCELED) {
198248
199249 }
200250 break ;
251+ case (REQUEST_FILE ): {
252+
253+ if (resultCode == Activity .RESULT_OK ) {
254+ Uri selectedImage = data .getData ();
255+
256+
257+ // mCompressor = new FileCompressor(mContext);
258+ File mPhotoFile = null ;
259+ mPhotoFile = new File (ImageUtil .getRealPathFromUri (mContext , selectedImage ));
260+
261+ if (pickerCallback != null ) {
262+ pickerCallback .onMediaFilePicked (mPhotoFile .getAbsolutePath ());
263+ }
264+
265+ }
266+ }
267+ break ;
201268 case (REQUEST_GALLERY_PHOTO ): {
202269
203270
0 commit comments