skip to Main Content

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


  1. I can’t get access to the file or ‘READ_EXTERNAL_STORAGE’ by Karumi Dexter. It is working till Sdk-32 but it’s not working on the 33.

    As it is mentioned on the official page, the Dexter library:

    Is no longer under active development.

    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:

    Starting in API level 33, this permission has no effect. If your app accesses other apps’ media files, request one or more of these permissions instead: READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, READ_MEDIA_AUDIO. Learn more about the storage permissions that are associated with media files.

    So most likely that’s the reason why you get that behavior.

    Login or Signup to reply.
  2. For using Intent.ACTION_GET_CONTENT you have never needed permission READ_EXTERNAL_STORAGE.

    For no Android version.

    So remove the check and just launch the intent.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search