I need in my project to make a snapshot for current activity (whole main layout) in Android, I attempt many ways but always I get error which "open failed eacces (permission denied) at cretenewFile()" My code like this:
public void TakeSnapshoot(){
mainlayout.setDrawingCacheEnabled(true);
Bitmap b = mainlayout.getDrawingCache();
String extr = Environment.getExternalStorageDirectory().toString()
+ "/SaveCapture";
File myPath = new File(extr);
if (!myPath.exists()) {
boolean result = myPath.mkdir();
Toast.makeText(this, result + "", Toast.LENGTH_SHORT).show();
}
myPath = new File(extr, getString(R.string.app_name) + ".jpg");
Toast.makeText(this, myPath.toString(), Toast.LENGTH_SHORT).show();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getContentResolver(), b,
"Screen", "screen");
} catch (FileNotFoundException e) {
e.printStackTrace();
//Log.e("Error", e + "");
}
catch (Exception e) {
e.printStackTrace();
//Log.e("Error", e + "");
}
}
The AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="SOA.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<!-- Network State Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- For android different screen sizes -->
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true"
/> ...
after take a snapshot then I can print what I want!? I thought this way is best way to print current activity in android?! Please any idea or help will be appreciated !