我的手机是4.2.2。我正在运行android studio
在我的mainActivity上:
startActivityForResult(new CameraStuff().createCustomDialogCamGallery(this,
getCurrentPhotoPath()), REQUEST_IMAGE_OPTIONS);
我显示自定义对话框的代码是:
public Intent createCustomDialogCamGallery(Activity activity,String fullCameraActivityPath){
// Camera.
final List<Intent> cameraIntents = new ArrayList<Intent>();
if(!checkCam(activity).equals(NO_CAM)) {
final Intent captureIntent = new Intent(android.provider.MediaStore
.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = activity.getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities
(captureIntent, 0);
for (ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res
.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fullCameraActivityPath);
cameraIntents.add(intent);
}
}
// Filesystem.
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_PICK);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Foto");
// Add the camera options.
if(!checkCam(activity).equals(NO_CAM)) {
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new
Parcelable[cameraIntents.size()]));
}
return chooserIntent;
打开自定义对话框,其中包含相机和图库选项。当我选择相机并拍摄时:
在使用我的小型Android 4.2.2手机拍摄时,onActivityResult中的data.getData()得到了null。
在拍摄我的三星Galaxy S4 4.2.2时,我获得了data.getdata()值。 我实现了data.getData()附带的调试:content:// media / external / images / media / 2846
我该如何解决这个问题?
答案 0 :(得分:0)
fullCameraActivityPath必须是URI。 我将path参数作为String传递。那就是虫子......
intent.putExtra(MediaStore.EXTRA_OUTPUT, fullCameraActivityPath);