1

I am having an issue with saving a picture to my phones External storage(getting permission denied) when searching for solutions I've found 3 different answers.

The first one is the uses-permission in the Manifest file, I already had this but i tried moving it around inside the manifest with no luck.

Second one is if its API 23 or above it must ask permission instead of being in the manifest but i am using API 15.

and lastly, because its a physical phone and not an emulator some people said it cannot access the external storage while plugged into a computer(because the computer is accessing it) but my phone is set to charging only, and ive also tried unplugging it with no luck

the only other thing i can think of is the phone is a Google Pixel so it does not have an SD card but i read on androids website that devices without an SD card option have a partition for External memory

Am i missing something?

Jake

EDIT:

Chunk of code:

private void takeScreenshot() {
    Date now = new Date();
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);

try {
    String mPath = Environment.getExternalStoragePublicDirectory(
         Environment.DIRECTORY_PICTURES).getAbsolutePath()
             +"/Screenshots/image"+now;

    // create bitmap screen capture
    View v1 = getWindow().getDecorView().getRootView();
    v1.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);

    File imageFile= new File(mPath);

    Log.e("ERROR",mPath);

    FileOutputStream outputStream =
       new FileOutputStream(imageFile);
    int quality = 100;
    bitmap.compress(Bitmap.CompressFormat.JPEG,
        quality, outputStream);
    outputStream.flush();
    outputStream.close();
} catch (Throwable e) {
    e.printStackTrace();
}
}

Error Log:

09-08 16:59:25.774 13514-13514/com.example.jake.wellsfargo E/ERROR: /storage/emulated/0/Pictures/Screenshots/imageFri Sep 08 16:59:25 EDT 2017
09-08 16:59:25.776 13514-13514/com.example.jake.wellsfargo W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/Screenshots/imageFri Sep 08 16:59:25 EDT 2017 (Permission denied)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at java.io.FileOutputStream.open(Native Method)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:169)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at com.example.jake.wellsfargo.MainActivity.takeScreenshot(MainActivity.java:317)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at com.example.jake.wellsfargo.MainActivity.access$100(MainActivity.java:48)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at com.example.jake.wellsfargo.MainActivity$2.onClick(MainActivity.java:84)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at android.view.View.performClick(View.java:5637)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at android.view.View$PerformClick.run(View.java:22429)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at android.os.Handler.handleCallback(Handler.java:751)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at android.os.Looper.loop(Looper.java:154)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6121)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
09-08 16:59:25.777 13514-13514/com.example.jake.wellsfargo W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Jacob Hughes
  • 35
  • 1
  • 6
  • 1
    What do you mean by 'using API 15'? Are you running your app on API 15 (Ice Cream) Android, or you are compiling your app using API 15? Also the description you provided is a little bit vague. Could you please provide a piece of code you use to access external storage and exact text of error you are getting? – The Dreams Wind Sep 08 '17 at 20:40
  • I edited my original post with the log and chunk of code, and for API version, if i got to app->project structure it says sdk level is 15, either way, my network state uses permission in the manifest is working fine so im pretty sure it is under API level 23 – Jacob Hughes Sep 08 '17 at 21:12
  • See https://www.captechconsulting.com/blogs/runtime-permissions-best-practices-and-how-to-gracefully-handle-permission-removal (Android added new permission model for Android 6.0 Marshmallow) – Alexander Lubyagin Jan 31 '20 at 07:45

0 Answers0