我开发一个应用程序,其中图像取自原生相机应用。要被显示给用户。 在code我所做的是:
I am developing an app, where an image taken from the native camera app. is to be shown to the user. The code I did is:
/* Intent */ Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent, TAKE_PICTURE); /* Result */ onActivityResult(int requestCode, int resultCode, Intent returnIntent) { if(requestCode == TAKE_PICTURE) { //picture from Camera if (resultCode == Activity.RESULT_OK) { if(returnIntent != null) { try { // Get the file path where the image is stored. // This runs fine on all devices, except Samsung ones. Uri selectedImage = returnIntent.getData(); if(selectedImage == null) { if(returnIntent.getExtras() != null && returnIntent.getExtras().get(AppConstants.DATA) != null) { // But, I get the image Bitmap here. Means the image is stored in disk. Bitmap bmp = (Bitmap) returnIntent.getExtras().get(AppConstants.DATA); } } } catch (Exception e) { // } } } } }
这里的问题是,上述code正常工作的我尝试了所有设备(HTC的,SE的),但它在某种程度上未能在三星的。在乌里selectedImage = returnIntent.getData();永远不会返回任何东西。由于我的整个应用程序是建立在文件路径存储的这个逻辑,我无法继续。 有没有什么解决办法的人。
The problem here is, the above code works fine on all devices I tried (HTC's, SE's) but it somehow fails in the Samsung ones. The "Uri selectedImage = returnIntent.getData();" never returns anything. As my entire app is built over this logic of file path storing, I am not able to proceed. Is there any solution people.
推荐答案见的指定文件名指定的意图,它可以让你指定的文件名画面的EXTRA_OUTPUT参数图片应采取为code。还记得文件名时的活动结果被称为和使用,如果intent.getData为NULL
See Specify filename for picture to be taken for code to specify an EXTRA_OUTPUT parameter for the Intent which lets you specify a filename for the picture. Remember the filename when the activity result is called and use that if the intent.getData is NULL
如果你读这个bug报告中的其他意见,你会发现有多少的问题,照片拍摄于Android已经。
And if you read the other comments in that bug report, you'll realize how many problems that picture taking on Android has.
更多推荐
安卓三星:相机的应用程序将不会返回intent.getData()
发布评论