17
17
package com .jaiselrahman .filepicker .adapter ;
18
18
19
19
import android .app .Activity ;
20
+ import android .content .ContentValues ;
20
21
import android .content .Intent ;
21
22
import android .net .Uri ;
22
23
import android .provider .MediaStore ;
38
39
import com .jaiselrahman .filepicker .utils .TimeUtils ;
39
40
import com .jaiselrahman .filepicker .view .SquareImage ;
40
41
42
+ import java .io .File ;
41
43
import java .text .SimpleDateFormat ;
42
44
import java .util .ArrayList ;
43
45
import java .util .Date ;
@@ -57,7 +59,7 @@ public class FileGalleryAdapter extends MultiSelectionAdapter<FileGalleryAdapter
57
59
private OnSelectionListener <ViewHolder > onSelectionListener ;
58
60
private boolean showCamera ;
59
61
private boolean showVideoCamera ;
60
- private String filePath ;
62
+ private File lastCapturedFile ;
61
63
private SimpleDateFormat TimeStamp = new SimpleDateFormat ("yyyyMMdd_HHmmss" , Locale .getDefault ());
62
64
63
65
public FileGalleryAdapter (Activity activity , ArrayList <MediaFile > mediaFiles , int imageSize , boolean showCamera , boolean showVideoCamera ) {
@@ -78,8 +80,8 @@ else if (showCamera || showVideoCamera)
78
80
setItemStartPostion (1 );
79
81
}
80
82
81
- public String getLastCapturedFilePath () {
82
- return filePath ;
83
+ public File getLastCapturedFile () {
84
+ return lastCapturedFile ;
83
85
}
84
86
85
87
@ NonNull
@@ -156,27 +158,34 @@ private void handleCamera(ImageView openCamera, final boolean forVideo) {
156
158
public void onClick (View v ) {
157
159
Intent intent ;
158
160
String fileName ;
159
- java .io .File file , dir ;
161
+ File dir ;
162
+ Uri externalContentUri ;
160
163
if (forVideo ) {
161
164
intent = new Intent (MediaStore .ACTION_VIDEO_CAPTURE );
162
165
fileName = "/VID_" + getTimeStamp () + ".mp4" ;
163
166
dir = getExternalStoragePublicDirectory (DIRECTORY_MOVIES );
167
+ externalContentUri = MediaStore .Video .Media .EXTERNAL_CONTENT_URI ;
164
168
} else {
165
169
intent = new Intent (MediaStore .ACTION_IMAGE_CAPTURE );
166
170
dir = getExternalStoragePublicDirectory (DIRECTORY_PICTURES );
167
171
fileName = "/IMG_" + getTimeStamp () + ".jpeg" ;
172
+ externalContentUri = MediaStore .Images .Media .EXTERNAL_CONTENT_URI ;
168
173
}
169
174
if (!dir .exists () && !dir .mkdir ()) {
170
175
Log .d (TAG , "onClick: " +
171
176
(forVideo ? "MOVIES" : "PICTURES" ) + " Directory not exists" );
172
177
return ;
173
178
}
174
- file = new java .io .File (dir .getAbsolutePath () + fileName );
175
- filePath = file .getAbsolutePath ();
179
+ lastCapturedFile = new File (dir .getAbsolutePath () + fileName );
176
180
177
181
Uri fileUri = FileProvider .getUriForFile (activity ,
178
182
"com.jaiselrahman.filepicker.provider" ,
179
- file );
183
+ lastCapturedFile );
184
+
185
+ ContentValues values = new ContentValues ();
186
+ values .put (MediaStore .MediaColumns .DATA , lastCapturedFile .getAbsolutePath ());
187
+ activity .getContentResolver ().insert (externalContentUri , values );
188
+
180
189
intent .putExtra (MediaStore .EXTRA_OUTPUT , fileUri );
181
190
activity .startActivityForResult (intent , CAPTURE_IMAGE_VIDEO );
182
191
}
0 commit comments