【发布时间】:2014-10-27 08:15:03
【问题描述】:
我正在创建一个 Android 应用程序,它会截取屏幕截图并将其保存在 App image 文件夹中,这是我用于创建文件夹并保存屏幕截图的代码:
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/Porte3D");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
// Write your image name here
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
我正在使用 2 台设备(三星 Galaxy S2 和 moto G)对此进行测试,在 S2 上创建了文件夹并正确存储了图像,但 moto G 崩溃并出现以下错误:
10-27 09:09:41.422: A/libc(12069): Fatal signal 6 (SIGABRT) at 0x00002f25 (code=-6), thread 12435 (Thread-62263)
有谁知道如何解决这个问题以便在每台设备上都能正常工作?
【问题讨论】:
-
使用前必须确保 ExternalStorage 可用
-
这不是错误,ExternalStorage 在我的 Moto G 上可用
-
还有一件事 sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));这在 KitKat 中已被弃用,尽管这不是你崩溃的原因,但我只是跳出来,粘贴你的完整崩溃日志
-
您是否允许在清单中使用外部存储?
-
是的,@GeorgeThomas 我收到的崩溃日志只是我发布的那一行,我没有收到任何其他错误
标签: android