简体   繁体   中英

Permission Denied, while writing a image file file in Android SDcard

I am getting a problem while writing file at SDCARD. it shows as Permission denied.

I added " uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" "

On my Manifest,

public static void takeScreenshotd(View view, String name)throws Exception{

     view.setDrawingCacheEnabled(true);
     view.buildDrawingCache();
     String state = Environment.getExternalStorageState();
     Bitmap bitMap = view.getDrawingCache();
     FileOutputStream fos = null;
     File outputFile=new File(SCREENSHOT_LOCATION+name+"_"+System.currentTimeMillis()+"jpg");

     try{
         File sddirFile = new File(SCREENSHOT_LOCATION);
         if (!sddirFile.exists())
         {
             new File(SCREENSHOT_LOCATION).mkdirs();
            // sddirFile.mkdirs();
         }
         if(!sddirFile.canWrite())
         {
            boolean dr = sddirFile.setWritable(true);
             String Ak ="Protected";
         }

     fos = new FileOutputStream(outputFile);
    // It is skip this place.. when i keep the bitmap.compress (it shows an error message as permission denied.
         if (fos!=null)
         {
             bitMap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
             fos.close();
         }

     }catch (Exception e){
         e.printStackTrace();
     }

 }

检查您是否已在清单中添加此权限

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM