Devendra Kumar

Devendra Kumar

  • NA
  • 500
  • 164.4k

External storage access denied in xamarin android

Jan 19 2018 3:22 AM
Hello all
I just started building apps using xamarin.android and I got stuck in between.
I am working with images and uses the compress function of bitmap and when I read/write image on phone memory, it works fine but when I tried to write on ezxternal sd card, it shows access denied exception, although reading from it is working fine.I had also set the permission of ReadExternalStorage and WriteExternalStorage but still getting the exception.
 
Here is my code
  1. // Path of PhotoUri and path that I retreived  
  2. //var PhotoUri = {content://com.android.providers.media.documents/document/image%3A9104}  
  3.   
  4. //var path = /storage/D660-18BD/memorytest/20170930_230230.jpg  
  5.   
  6.   
  7. using (var bmp = MediaStore.Images.Media.GetBitmap(ContentResolver, PhotoUri))    
  8. {    
  9. var fullPath = System.IO.Path.GetFullPath(path);    
  10. var dirName = System.IO.Path.GetDirectoryName(fullPath);    
  11. var filename = System.IO.Path.GetFileNameWithoutExtension(fullPath);    
  12. var ext = System.IO.Path.GetExtension(fullPath);    
  13. var newname = System.IO.Path.Combine(dirName, filename + "IR" + ext);    
  14.     
  15. var fs = new FileStream(newname, FileMode.OpenOrCreate);  // here I got the exception  
  16. bmp.Compress(Bitmap.CompressFormat.Jpeg, 90, fs);    
  17. fs.Close();    
  18. fs.Dispose();    
  19. }    
Access to the path "/storage/D660-18BD/memorytest/20170930_230230IR.jpg" is denied.
 
Can anyone help me to get the solution. 

Answers (2)