大佬教程收集整理的这篇文章主要介绍了android – 如果相机旋转,来自相机的图像为null,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public void openImageIntent() { // Determine Uri of camera image to save. final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MyAppImages" + File.separator); root.mkdirs(); SimpleDateFormat sdf = new SimpleDateFormat("ddMMyy-hhmmss"); final String fname = String.format("%s.jpg",sdf.format(new Date())); final File sdImageMainDirectory = new File(root,fName); outputFileUri = Uri.fromFile(sdImageMainDirectory); // Camera. final List<Intent> cameraIntents = new ArrayList<Intent>(); final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); final PackageManager packageManager = 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,outputFileUri); cameraIntents.add(intent); } // Filesystem. final Intent galleryIntent = new Intent(); galleryIntent.setType("image/*"); galleryIntent.setAction(Intent.ACTION_GET_CONTENT); // Chooser of filesystem options. final Intent chooserIntent = Intent.createChooser(galleryIntent,"SELEct source"); // Add the camera options. chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,cameraIntents.toArray(new Parcelable[] {})); startActivityForResult(chooserIntent,SELECT_PICTURE_requEST); }
和onActivityResult方法:
protected void onActivityResult(int requestCode,int resultCode,Intent data) { if (resultCode == RESULT_OK) { if (requestCode == SELECT_PICTURE_requEST) { final Boolean isCamera; if (data == null) { isCamera = true; } else { final String action = data.getAction(); if (action == null) { isCamera = false; } else { isCamera = true; } } Uri SELEctedImageUri; if (isCamera) { SELEctedImageUri = outputFileUri; } else { SELEctedImageUri = data == null ? null : data.getData(); } if (imageDelegate != null) { Log.e(tag,"imageDelegate not null: " + imageDelegatE); imageDelegate.gotNewImageUri(SELEctedImageUri); imageDelegate = null; } else if (getSupportFragmentManager().findFragmentByTag("addofferdialog") != null) { imageDelegate = (AddOfferFragment) getSupportFragmentManager().findFragmentByTag("addofferdialog"); Log.e(tag,"imageDelegate is null but found fragment: " + imageDelegatE); Log.e(tag,"Activity image: " + SELEctedImageUri); imageDelegate.gotNewImageUri(SELEctedImageUri); imageDelegate = null; } else { Log.e(tag,"cAnnot find imageDelegate!!!!"); } Log.e(tag,"SELEctedImageUri: " + SELEctedImageUri); } } }
以上是大佬教程为你收集整理的android – 如果相机旋转,来自相机的图像为null全部内容,希望文章能够帮你解决android – 如果相机旋转,来自相机的图像为null所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。