Skip to content

Commit

Permalink
fix: android 14 selected file permission changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gowtham-13309 committed Feb 29, 2024
1 parent 0adad7a commit b8b8157
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
16 changes: 15 additions & 1 deletion app/src/main/java/com/gowtham/videotrimmer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,21 @@ private long getEdtValueLong(EditText editText) {
}

private boolean checkCamStoragePer() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
boolean hasPermission= ContextCompat.checkSelfPermission(this, Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)
== PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(this, Manifest.permission.READ_MEDIA_VIDEO)
== PackageManager.PERMISSION_GRANTED;
boolean hasCamera= ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED;
if(hasPermission && hasCamera){
return true;
}else {
return checkPermission(
Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.CAMERA);
}

} else if(Build.VERSION.SDK_INT == Build.VERSION_CODES.TIRAMISU)
{
return checkPermission(
Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.CAMERA);
Expand Down
1 change: 1 addition & 0 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />

Expand Down
31 changes: 23 additions & 8 deletions library/src/main/java/com/gowtham/library/ui/ActVideoTrimmer.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private void setDataInView() {
try {
Runnable fileUriRunnable = () -> {
Uri uri = Uri.parse(bundle.getString(TrimVideo.TRIM_VIDEO_URI));
String path= FileUtilKt.getValidatedFileUri(ActVideoTrimmer.this,uri);
String path = FileUtilKt.getValidatedFileUri(ActVideoTrimmer.this, uri);
filePath = Uri.parse(path);
runOnUiThread(() -> {
LogMessage.v("VideoUri:: " + uri);
Expand Down Expand Up @@ -337,7 +337,7 @@ private void loadThumbnails() {
try {
long diff = totalDuration / 8;
int sec = 1;
File videoFile= new File(filePath.toString());
File videoFile = new File(filePath.toString());
for (ImageView img : imageViews) {
long interval = (diff * sec) * 1000000;
RequestOptions options = new RequestOptions().frame(interval);
Expand Down Expand Up @@ -475,8 +475,8 @@ protected void onDestroy() {
videoPlayer.release();
if (progressView != null && progressView.isShowing())
progressView.dismiss();
File f=new File(getCacheDir(), "temp_video_file");
if(f.exists()){
File f = new File(getCacheDir(), "temp_video_file");
if (f.exists()) {
f.delete();
}
stopRepeatingTask();
Expand Down Expand Up @@ -697,12 +697,27 @@ private void showProcessingDialog() {
}

private boolean checkStoragePermission() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
{
Uri uri = Uri.parse(bundle.getString(TrimVideo.TRIM_VIDEO_URI));
String fileUri= FileUtilKt.getActualFileUri(this, uri);
if(fileUri!=null && new File(fileUri).canRead()){
return true;
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
boolean hasPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)
== PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(this, Manifest.permission.READ_MEDIA_VIDEO)
== PackageManager.PERMISSION_GRANTED;
if (hasPermission) {
return true;
} else {
return checkPermission(
Manifest.permission.READ_MEDIA_VIDEO);
}
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.TIRAMISU) {
return checkPermission(
Manifest.permission.READ_MEDIA_VIDEO);
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
return checkPermission(
Manifest.permission.READ_EXTERNAL_STORAGE);
} else
Expand Down

0 comments on commit b8b8157

Please sign in to comment.