インテントの null を取得するインテントonActivityResult
を開始すると、インテント データをメソッドに渡すという問題に直面しています。ACTION_IMAGE_CAPTURE
カメラのアクティビティを開始し、データをonActivityResult()
何がうまくいかなかったのかわからない奇妙な私を助けてください
事前に感謝
public void takePicture()
{
File directory = new File(Environment.getExternalStorageDirectory() + "/AML_AttachmentImages" + "/");
if (!directory.exists())
{
directory.mkdir();
}
int count = 0;
if (directory != null)
{
File[] files = directory.listFiles();
if (files != null)
{
count = files.length;
}
}
count++;
String imagePath = "AML_IMAGE_" + count + ".jpg";
File file = new File(directory, imagePath);
outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PHOTO_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK)
{
switch (requestCode)
{
case TAKE_PHOTO_CODE :
outputFileUri=data.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
File imageFilePath = new File(outputFileUri.getPath());
imagePathUris.add(imageFilePath.getAbsolutePath());
Bitmap myBitmap = BitmapFactory.decodeFile(imageFilePath.getAbsolutePath());
bitmaps.add(myBitmap);
txtAttachmentsCount.setVisibility(View.VISIBLE);
txtAttachmentsCount.setText(getResources().getString(R.string.view_attachment_text) + Integer
.toString(imagePathUris.size()) + ")");
break;
case REQ_PIC :
final ContentResolver cr = getContentResolver();
final String[] p1 = new String[]{MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATE_TAKEN};
Cursor c1 = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null, null, p1[1] + " DESC");
if (c1.moveToFirst())
{
String uristringpic = "content://media/external/images/media/" + c1.getInt(0);
Uri newuri = Uri.parse(uristringpic);
Log.i("TAG", "newuri " + newuri);
}
c1.close();
break;
}
}
}