MediaLibrary creates assets twice on Android device

Please provide the following:

  1. SDK Version: 47.0
  2. Platforms(Android/iOS/web/all):Android
  3. Add the appropriate “Tag” based on what Expo library you have a question

A couple of issues I’ve noticed with mediaLibrary on Android.

If the copy flag is set to false in createAlbumAsync or addAssetsToAlbumAsync, the procedure fails with a “need WRITE_EXTERNAL_PERMISSIONS “ error.

Also when saving or creating an asset, there are two copies stored in the shared media, one in an asset folder and another in the media type folder.

Below is my code and the workflow as I now understand. Firstly to store a file in the Local shared folders you have to create an asset, in my case its a photo and creates a file in the DCIM folder. Then, to store it in an album I use MediaLibrary.createAlbumAsync(albumName, asset, false); which requires the asset as an argument. When the flag is set to false in this command, it tries to delete the file/asset in the DCIM folder and it always asks me for permissions on my android phone which is undesirable.

Also when switching to save an audio recording and the flag is set to false I get the following error: [Error: Could not get albums: need WRITE_EXTERNAL_STORAGE permission.]

Any help would be appreciated.

 const perms=await MediaLibrary.requestPermissionsAsync();
    if (perms.granted){
       
        const asset = await MediaLibrary.createAssetAsync(fileUri)
     
        const album = await MediaLibrary.getAlbumAsync(albumName);
        
      
        if (album == null){
          
            try {
                await MediaLibrary.createAlbumAsync(albumName, asset, false);
            } catch (error) {
               
            }
           
          }
          else{ 
          
            await MediaLibrary.addAssetsToAlbumAsync(asset, album, false);
            
          }
   
    }

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.