'Android 11 Scoped storage permissions SK

My App use the file paths of images and music and videos provided by Environment.getExternalStorageDirectory() to create albums of photos, but with Android 11 I won't be able to access directly files.

According to the Android developers documentation they recently introduced the MANAGE_EXTERNAL_STORAGE permission, but it's didn't work with me .

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />


android:requestLegacyExternalStorage="true"

        public void onClick(View v) {
        //    R.raw.tunejonakaha, R.raw.kuch_is_tarah_atif_aslam_sad_love_song, R.raw.happy_music, R.raw.meherbani, R.raw.party_on_my_mind_ft_kk
            final int[] mSongs = new int[]{};
            //"tune jo na kaha", "kuch_is_tarah_atif_aslam_sad_love_song", "happy_music","meherbani", "party_on_my_mind_ft_kk"
            final String[] mSongsName = new String[]{};
            for (int i = 0; i < mSongs.length; i++) {
                try {
                  //  String path = Environment.getExternalStorageDirectory() +"/RawMusic";
                    String path = Constance.rawMusicDirectory;
                    Log.d("pathaaaaaaaa", "" + path);
                    File dir = new File(path);
                    if (dir.mkdirs() || dir.isDirectory()) {
                        // String str_song_name = i + ".mp3";
                        String str_song_name = mSongsName[i] + ".mp3";

                        CopyRAWtoSDCard(mSongs[i], path + File.separator + str_song_name);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            Intent intentMusic1 = new Intent(context, ActivityRawMusic.class);
            //intentMusic.putExtra("checkForMusic", true);
            startActivityForResult(intentMusic1, REQUEST_Music);

        }

public class Constance {

public static File FileDirectory = Environment.getExternalStoragePublicDirectory("Full Screen Video Creator" + "/");
public static final File CACHE_MUSIC_DIRECTORY = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "FullScreen_Video_Creator_Music");
public static final File CACHE_MUSIC_File = new File(CACHE_MUSIC_DIRECTORY, "defaultmusic.mp3");
public static final String rawMusicDirectory=Environment.getExternalStorageDirectory() + "/FullScreenRawMusic";

Is there anyone who better understood the Android Documentation???



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source