0

写真を撮ってメモリに保存するカメラアクティビティを作成しましたが、保存された写真のURIにアクセスするにはどうすればよいですか?

これが私のカメラアクティビティのコードです:

    public void onPictureTaken(byte[] data, Camera camera) {

        File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
        if (pictureFile == null){
            Log.d("Errore Doorbin", "Error creating media file, check storage permissions: ");
            return;
        }

        try {
            FileOutputStream fos = new FileOutputStream(pictureFile);
            fos.write(data);
            fos.close();
            // these lines are for the gallery to scan the SDCard manually
            File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_PICTURES), "MyCameraApp");
                sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, 
                    Uri.parse("file://"+ mediaStorageDir)));
           /* MediaScannerConnection.scanFile(CameraActivity.this,
                    new String[] { fos.toString() }, null,
                    new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {
                    // code to execute when scanning is complete
                }
           });*/
           // fos.close();
        } catch (FileNotFoundException e) {
            Log.d("Errore Doorbin", "File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d("Errore Doorbin", "Error accessing file: " + e.getMessage());
        }
        catch (Exception e)
        {
            Log.d("Errore Doorbin", "errore Kolli dade!" + e.getMessage()) ;
        }
    }
};
4

1 に答える 1

0

このアクティビティによって取得されるファイルはです。したがって、そのUriにアクセスするには、次のようなpictureFileUriの関数を使用する必要があります。fromFile()

Uri photoUri = Uri.fromFile(pictureFile);

于 2013-02-19T12:40:57.370 に答える