Android Lollipop camera issue

落爺英雄遲暮 提交于 2019-12-08 04:42:45

问题


My android application was working fine on all android devices from version 2.3 to 4.4. However, when i updated my Samsung Galaxy S4 to LOLLIPOP and tested the said app, there are a few errors in functionalities such as camera,map etc.

Below is the code snippet used in my application to utilize the native camera:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult( requestCode,  resultCode,  data);
   if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK && null != data) 
   {    
      Bitmap camImg = (Bitmap) data.getExtras().get("data");
   }
}

Here I am getting (Bitmap) data.getExtras().get("data") as null. Is there any alternate solution for this code. Any help would be appreciated.


回答1:


You would appear to be following the documentation, and it would appear that the camera app that is being chosen here is not.

This is one of the risks in delegating work like this to a third-party app -- third-party apps can have bugs.

Your choices are:

  1. Switch to using EXTRA_OUTPUT to specify a Uri for a full-size image. In your results, if you do not have the data Bitmap, try reading in the full-size image, using BitmapFactory.Options to down-sample it to something more appropriately sized. There may still be camera apps that honor ACTION_IMAGE_CAPTURE that do not work, but it should reduce the number of such broken apps.

  2. Use the android.hardware.Camera or android.hardware.camera2 APIs yourself, and avoid relying upon a third-party app.




回答2:


I would have to disagree with CommonsWare on this one. I am using the android.hardware.Camera with my app and testing with a Samsung Galaxy S4 running Lollipop. It seems the problem is that onCreate is called before onActivityResult when running the app on Samsung Lollipop.

My suggestion is to set the max target in your app to 20 (Android 4.4) until Samsung sorts this out. It is a Samsung issue.

 android:maxSdkVersion="20"


来源:https://stackoverflow.com/questions/29145976/android-lollipop-camera-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!