我創建一個Android應用程序,需要一個屏幕截圖並保存在App圖像文件夾的時候,這是我用它來創建文件夾並保存截圖中的代碼:崩潰創建圖像文件夾
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和摩托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可使用它 – 2014-10-27 08:16:16
這不是錯誤之前,該ExternalStorage可以用我的Moto G的 – Signo 2014-10-27 08:24:52
一件事sendBroadca st(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse(「file://」+ Environment.getExternalStorageDirectory()))); 這是棄用從KitKat,雖然它不是你崩潰的原因,我剛剛出題,粘貼年完整的崩潰日誌 – 2014-10-27 08:27:00