Function for choosing video .
private void ChooseVideo(){
Dexter.withContext(this)
.withPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
.withListener(new PermissionListener() {
@Override public void onPermissionGranted(PermissionGrantedResponse response) {
Intent intent = new Intent( );
//new line added
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType( "video/*" );
intent.setAction( Intent.ACTION_GET_CONTENT );
startActivityForResult( intent,102 );
}
@Override public void onPermissionDenied(PermissionDeniedResponse response) {
}
@Override public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {
token.continuePermissionRequest();
}
}).check();
}
//on activity result
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult( requestCode, resultCode, data );
if (requestCode==102 &resultCode==RESULT_OK);
videoUri=data.getData();
binding.VideoViewAVA.setVisibility(View.VISIBLE);
binding.VideoViewAVA.setVideoURI(videoUri);
Cursor mCursor = getApplicationContext().getContentResolver().query( videoUri,null,null,null,null );
int indexedName =mCursor.getColumnIndex( OpenableColumns.DISPLAY_NAME );
mCursor.moveToFirst();
songName = mCursor.getString(indexedName);
finalSongTitle = songName.replace(".mp4","")
.replace(".wmv","")
.replace(".webm","")
.replace(".mkv"," ");
mCursor.close();
binding.btnUploadVideo.setEnabled(true);
binding.vTitle.setText(finalSongTitle);
}
[Output should be look Like This]
But it’s not working properly.(https://phpout.com/wp-content/uploads/2023/09/bAsZu.png)
2
Answers
As it is mentioned on the official page, the Dexter library:
And this has been happening for 2 years now. So it can work with Sdk-32 but not with Sdk-33 because it isn’t maintained anymore. My recommendation in such cases would be to use your own logic regarding permission as it is mentioned in the official Android documentation. Please also see that there is a note there regarding the
READ_EXTERNAL_STORAGE
that says:So most likely that’s the reason why you get that behavior.
For using
Intent.ACTION_GET_CONTENT
you have never needed permissionREAD_EXTERNAL_STORAGE
.For no Android version.
So remove the check and just launch the intent.