0

私のAndroidデバイスがカメラから撮った画像を保存するディレクトリを見つける方法についてのガイドラインを教えてください。

次のコード スニペットでは、カメラ アプリを起動する前にファイルのリストを取得するつもりです。カメラ アプリから戻るときに、同じディレクトリ内のすべてのファイルのリストを取得し、新しく追加されたファイルを処理します。

public void onBtnTakePhoto(final View view) {
    existingfiles = UploadImageService.getFiles(<IMAGE_LOCATION>);
    final Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
    startActivityForResult(intent, TAKE_PICTURE);
}


public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
        case TAKE_PICTURE:
            List<String> newFies = UploadImageService.getFiles(<IMAGE_LOCATION>);
            newFies.removeAll(existingfiles);
            for (String newFile : newFies) {
                File file = new File(newFile);
                addImage( Uri.fromFile(file), PictureSource.CAMERA);
            }
            break;
    }
    // regardless of which activity, check that files exist:
    verifyFilesExist(images);
}
4

1 に答える 1

1

私が理解している限りでは、実際にはACTION_IMAGE_CAPTURE(INTENT_ACTION_STILL_IMAGE_CAMERA ではなく) アクションでインテントを起動する必要があります。次に、onActivityResultインテントからデータを取得する必要があります。そこに画像への参照があります。

ここで与えられた例を見てください。

しかし、あなたの答えを見ると、おそらくこれがより便利であることがわかるでしょう:

String[] projection = { 
          MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA 
}; 
String selection = ""; 
String[] selectionArgs = null; 
mImageExternalCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
           projection, selection, selectionArgs, null); 
mImageInternalCursor = 
           managedQuery(MediaStore.Images.Media.INTERNAL_CONTENT_URI, projection,
           selection, selectionArgs, null); 

それから

String filePath = 
            mImageExternalCursor.getString(mImageExternalCursor.getColumnIndexOrThrow(
            Media‌Store.Images.ImageColumns.DATA));

(実際には新しい写真を撮りたくないため)。

于 2013-05-14T15:56:13.243 に答える