gpt4 book ai didi

android - 访问android SD卡

转载 作者:行者123 更新时间:2023-11-30 03:43:26 27 4
gpt4 key购买 nike

我试图将我当前的 webview 保存在 android 的缓存中(有人告诉我 mnt/sdcard)但是无论是使用文件资源管理器还是尝试在代码中写入它我在我的 avd 模拟器上收到这个错误:

java.io.FileNotFoundException:/mnt/sdcard/imageFolder/page.jpg: 打开失败:EACCES(权限被拒绝)

我也尝试先创建目录,但 mkdir() 函数返回 false。 我的 list 中有权限行:

<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());
}
}

最佳答案

这可能是因为您的 AVD 在创建时可能没有 SD 卡。

选择您的虚拟设备 -> 编辑 -> 检查 SD 卡字段

如果此处为空,请在此处输入尺码。然后重新运行您的应用程序。

关于android - 访问android SD卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15400496/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com