Я получил решение по вышеуказанной проблеме.
cvMain.setDrawingCacheEnabled(true);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "DEMO_" + timeStamp;
String path = createWorkingDirectory().getAbsolutePath() + "/" + imageFileName + ".jpg";
File fileTemp = new File(path);
if (!fileTemp.exists()) {
try {
fileTemp.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
Bitmap b = cvMain.getDrawingCache();
OutputStream stream = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri filePathUri = FileProvider.getUriForFile(MainActivity.this, "demoApp", fileTemp);
try {
stream = getContentResolver().openOutputStream(filePathUri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (stream != null) {
b.compress(Bitmap.CompressFormat.JPEG, 95, stream);
}
} else {
try {
stream = new FileOutputStream(fileTemp);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (stream != null)
b.compress(Bitmap.CompressFormat.JPEG, 95, stream);
}
try {
if (stream != null)
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
cvMain.setDrawingCacheEnabled(false);
file_provider.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="demoApp"
path="." />
</paths>
AndroidManifest.xml внутри тега
<provider android:name="android.support.v4.content.FileProvider"
android:authorities="demoApp"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider" />
</provider>
Добавлен build.gradle (приложение)
implementation 'com.android.support:support-v4:27.1.1'