I receive this error:
remove failed: ENOENT (No such file or directory) : /storage/emulated/0/screenShot.jpg
FileNotFoundException: /storage/emulated/0/screenShot.jpg: open failed: EACCES (Permission denied)
while running this screenshot method (the error points at the FileOutputStream creation from the imageFile, after "else"):
public void shareScreenshot(View v){
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh-mm-ss", now);
CharSequence nowStr = DateFormat.format("yyyy-MM-dd_hh-mm-ss", now);
try {
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + "screenShot" + ".jpg";
// 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);
if(imageFile.delete()){
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
startShareIntent(imageFile);
}else{
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
startShareIntent(imageFile);
}
} catch (Throwable e) {
// Several error may come out with file handling or OOM
e.printStackTrace();
Toast.makeText(this,"Something went wrong, try again.", Toast.LENGTH_SHORT).show();
}
}
And here's my manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>