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)