2016-03-21 134 views
1

我在Android工作室製作了一個Android應用程序,用戶可以拍攝照片並將其保存到畫廊的新文件夾中。目前,該應用程序拍攝的照片很好,但不會將圖像保存到我的圖庫中新的「SOC」文件夾中。我沒有收到任何錯誤,我不知道爲什麼它不保存圖像。任何幫助,將不勝感激。將圖像保存到我的圖庫

我的代碼休耕

static final int REQUEST_IMAGE_CAPTURE = 1; 
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 0; 
public void onClickbtnCamera(View v) 
{ 
    Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 
    Uri uriSavedImage=Uri.fromFile(new File("/storage/emulated/0/DCIM/SOC","QR_"+timeStamp+ ".png")); 
    imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); 
    startActivityForResult(imageIntent, 1); 
} 



    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if (requestCode == 1) { 

      //Check for succesful result code 
      if (resultCode == -1) { 
       //Show your Toast when the result is a success. 
       Toast toast = Toast.makeText(getApplicationContext(), 
         "Picture is saved in your SOC gallery", Toast.LENGTH_SHORT); 
       toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 100, 0); 
       toast.show(); 
      } 
     } 
    } 
+0

如何落實活動結果? – Tony

+0

我是否在那裏添加了我的活動 –

+0

查看我編輯的答案 – Tony

回答

0

我認爲你必須手動添加新照片的URI媒體內容提供方。 看看here

+0

我認爲這可能是一個評論! – Eenvincible

+0

你不應該回答一個鏈接,沒有任何可能的片段! – Tony

0

調用此方法可在活動的結果

protected void addPhotoToGallery() { 
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); 
    File f = new File(getCurrentPhotoPath()); 
    Uri contentUri = Uri.fromFile(f); 
    mediaScanIntent.setData(contentUri); 
    this.getActivity().sendBroadcast(mediaScanIntent); 
} 

你應該啓動意圖,然後getCurrentPhotoPath(前將照片保存路徑)必須獲得該路徑

相關問題