1

我有以下代码可以从我的 Android 应用程序中打开相机应用程序。它在三星 Galaxy Nexus 上运行良好,但在三星 Galaxy S3 上崩溃,不幸的是我没有后一种设备来调试问题,有什么建议吗?

    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    File dir = new File(Environment.getExternalStorageDirectory() + File.separator + this.getString(R.string.kda_images));
    File file = new File(Environment.getExternalStorageDirectory() + File.separator + this.getString(R.string.kda_images) + File.separator + "Image-" + dir.listFiles().length + ".jpg");
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));//The selected image is created in the specified location: file
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));//Refreshes the directory to show the new image
    startActivityForResult(intent, CAPTURE_NEW_IMAGE);
4

1 回答 1

0

请尝试使用下面的代码,因为我最终在 Galaxy s3 设备中正常工作。

Intent action = new Intent("android.media.action.IMAGE_CAPTURE") action.putExtra(MediaStore.EXTRA_OUTPUT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString()); startActivityForResult(action,TAKE_PICTURE_FROM_CAMERA);

于 2013-07-01T06:33:33.600 回答