Skip to content

Commit b8b8157

Browse files
fix: android 14 selected file permission changes
1 parent 0adad7a commit b8b8157

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

app/src/main/java/com/gowtham/videotrimmer/MainActivity.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,21 @@ private long getEdtValueLong(EditText editText) {
272272
}
273273

274274
private boolean checkCamStoragePer() {
275-
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
275+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
276+
boolean hasPermission= ContextCompat.checkSelfPermission(this, Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)
277+
== PackageManager.PERMISSION_GRANTED
278+
|| ContextCompat.checkSelfPermission(this, Manifest.permission.READ_MEDIA_VIDEO)
279+
== PackageManager.PERMISSION_GRANTED;
280+
boolean hasCamera= ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
281+
== PackageManager.PERMISSION_GRANTED;
282+
if(hasPermission && hasCamera){
283+
return true;
284+
}else {
285+
return checkPermission(
286+
Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.CAMERA);
287+
}
288+
289+
} else if(Build.VERSION.SDK_INT == Build.VERSION_CODES.TIRAMISU)
276290
{
277291
return checkPermission(
278292
Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.CAMERA);

library/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
33

44
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
5+
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
56
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
67
android:maxSdkVersion="32" />
78

library/src/main/java/com/gowtham/library/ui/ActVideoTrimmer.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private void setDataInView() {
216216
try {
217217
Runnable fileUriRunnable = () -> {
218218
Uri uri = Uri.parse(bundle.getString(TrimVideo.TRIM_VIDEO_URI));
219-
String path= FileUtilKt.getValidatedFileUri(ActVideoTrimmer.this,uri);
219+
String path = FileUtilKt.getValidatedFileUri(ActVideoTrimmer.this, uri);
220220
filePath = Uri.parse(path);
221221
runOnUiThread(() -> {
222222
LogMessage.v("VideoUri:: " + uri);
@@ -337,7 +337,7 @@ private void loadThumbnails() {
337337
try {
338338
long diff = totalDuration / 8;
339339
int sec = 1;
340-
File videoFile= new File(filePath.toString());
340+
File videoFile = new File(filePath.toString());
341341
for (ImageView img : imageViews) {
342342
long interval = (diff * sec) * 1000000;
343343
RequestOptions options = new RequestOptions().frame(interval);
@@ -475,8 +475,8 @@ protected void onDestroy() {
475475
videoPlayer.release();
476476
if (progressView != null && progressView.isShowing())
477477
progressView.dismiss();
478-
File f=new File(getCacheDir(), "temp_video_file");
479-
if(f.exists()){
478+
File f = new File(getCacheDir(), "temp_video_file");
479+
if (f.exists()) {
480480
f.delete();
481481
}
482482
stopRepeatingTask();
@@ -697,12 +697,27 @@ private void showProcessingDialog() {
697697
}
698698

699699
private boolean checkStoragePermission() {
700-
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
701-
{
700+
Uri uri = Uri.parse(bundle.getString(TrimVideo.TRIM_VIDEO_URI));
701+
String fileUri= FileUtilKt.getActualFileUri(this, uri);
702+
if(fileUri!=null && new File(fileUri).canRead()){
703+
return true;
704+
}
705+
706+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
707+
boolean hasPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)
708+
== PackageManager.PERMISSION_GRANTED ||
709+
ContextCompat.checkSelfPermission(this, Manifest.permission.READ_MEDIA_VIDEO)
710+
== PackageManager.PERMISSION_GRANTED;
711+
if (hasPermission) {
712+
return true;
713+
} else {
714+
return checkPermission(
715+
Manifest.permission.READ_MEDIA_VIDEO);
716+
}
717+
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.TIRAMISU) {
702718
return checkPermission(
703719
Manifest.permission.READ_MEDIA_VIDEO);
704-
}
705-
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
720+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
706721
return checkPermission(
707722
Manifest.permission.READ_EXTERNAL_STORAGE);
708723
} else

0 commit comments

Comments
 (0)