我正在尝试将当前的 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());
}
}
}