簡體   English   中英

Android-如文檔所述,相機意圖未執行保存

[英]Android - Camera intent not performing save, as mentioned in documentation

我設置了攝像頭,以嘗試在設備的根目錄中創建文件。

File storagePath = new File(Environment.getExternalStorageDirectory()+ "/Football_Fans");
storagePath.mkdirs();
File file = new File(storagePath, "FAN_IMAGE_TEMP");                                

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);            

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, storagePath);
startActivityForResult(cameraIntent,CAMERA_REQUEST_IMAGE);

運行我的應用程序時,沒有任何activityOnResult設置,但是我使用fileExplorer嘗試查看是否創建了我的文件。 我的文件夾創建得很好,但是照片沒有顯示。 知道為什么嗎?

文檔指出,如果設置了EXTRA_OUTPUT ,它將寫入該位置。 所以我很困惑為什么它不起作用。

調用方可以傳遞一個額外的EXTRA_OUTPUT來控制該圖像的寫入位置。 如果不存在EXTRA_OUTPUT,則會在Extra字段中將一個小型圖像作為Bitmap對象返回。 這對於只需要較小圖像的應用程序很有用。 如果存在EXTRA_OUTPUT,則將全尺寸圖像寫入EXTRA_OUTPUT的Uri值。

使用Uri。 嘗試這個

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(storagePath));

“ ..將被寫入EXTRA_OUTPUT的Uri值。”

您正在傳遞一個File對象(storagePath)。 它期望一個Uri,所以使用這個:

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(storagePath));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM