2014-11-01 82 views
0

我試圖做一個應用程序,它基本上拍照並將它們保存在我已創建的文件夾中,但是當我檢查文件夾時,它是空的。有沒有辦法可以檢查我的文件是否真的被保存? 這裏是我的代碼:我的照片不被保存

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 
    filePathTop = "/TopClothes/Image_" + timeStamp + ".jpg" ; 
    //filePathBot = "/BottomClothes/Image_" + timeStamp + ".png" ; 

    File foldertop = new File(Environment.getExternalStorageDirectory() + "/TopClothes"); 
    File folderbot = new File(Environment.getExternalStorageDirectory() + "/BottomClothes"); 

    File image = new File(foldertop, "Image_" + timeStamp + ".jpg"); 
    uriSavedImage = Uri.fromFile(image); 
    boolean success = true; 

    if (!foldertop.exists()) { 
     success = foldertop.mkdir(); 
    } 

然後:

@Override 
public void onClick(View v) { 
    // TODO Auto-generated method stub 
    switch(v.getId()){ 
    case R.id.bCamera: 

     i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
     startActivityForResult(i, cameraData); 
     i.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); 


    break; 
    } 
} 
+1

你有沒有添加'<使用許可權android:name =「android.permission.WRITE_EXTERNAL_STORAGE」/>'清單的權限? – kevinkl3 2014-11-01 02:24:33

+0

@ kevinkl3是的,我有。 – GUZ 2014-11-01 02:34:26

回答

0
public void onClick(View v) { 
// TODO Auto-generated method stub 
switch(v.getId()){ 
case R.id.bCamera: 

    i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    i.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); 
    startActivityForResult(i, cameraData); 
break; 
} 

}

嘗試把圖像URI開始活動之前

+0

Omg,我不能相信那是錯誤!非常感謝你! – GUZ 2014-11-01 04:46:08