現在の WebView を Android のキャッシュに保存しようとしています (mnt/sdcard と言われました) が、ファイル エクスプローラーを使用するか、コードに書き込もうとすると、avd エミュレーターでこのエラーが発生します。
java.io.FileNotFoundException: /mnt/sdcard/imageFolder/page.jpg: open failed: EACCES (Permission denied)
私も最初にディレクトリを作成しようとしましたが、mkdir() 関数は false を返します。マニフェストに許可行があります。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
これが私のコードです:
public class screenCap extends DroidGap {
private WebView myAppView;
private DroidGap myGap;
public screenCap(DroidGap gap, WebView view)
{
myAppView = view;
myGap = gap;
}
//Captures the current webview and saves it as a jpeg so it can be loaded into
//the page flip html plugin
public void captureScreen(){
myAppView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
myAppView.draw(canvas);
//Create a directory to hold the temporary image
File f = new File(android.os.Environment.getExternalStorageDirectory()+"/imageFolder/"+ "page.jpg");
if (!f.getParentFile().exists());
{
f.getParentFile().mkdir();
Log.d("DIRECTORY MADE!","!!!");
}
try {
myAppView.getDrawingCache().compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(f));
} catch (Exception e) {
Log.e("Error--------->", e.toString());
}
}
}