简体   繁体   English

Android Lollipop相机问题

[英]Android Lollipop camera issue

My android application was working fine on all android devices from version 2.3 to 4.4. 我的android应用程序在版本2.3至4.4的所有android设备上均正常运行。 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. 但是,当我将Samsung Galaxy S4更新为LOLLIPOP并测试了该应用后,相机,地图等功能出现了一些错误。

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. 在这里,我得到(Bitmap)data.getExtras()。get(“ data”)为null。 Is there any alternate solution for this code. 此代码是否有其他替代解决方案。 Any help would be appreciated. 任何帮助,将不胜感激。

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. 切换到使用EXTRA_OUTPUT为全尺寸图像指定Uri 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. 在结果中,如果没有data Bitmap ,请尝试使用BitmapFactory.Options读取完整大小的图像,以将其缩减采样为更合适的大小。 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. 仍然可能有一些相机应用无法使用ACTION_IMAGE_CAPTURE ,但不能使用,但应减少此类损坏的应用的数量。

  2. Use the android.hardware.Camera or android.hardware.camera2 APIs yourself, and avoid relying upon a third-party app. 自己使用android.hardware.Cameraandroid.hardware.camera2 API,并避免依赖第三方应用程序。

I would have to disagree with CommonsWare on this one. 在这一点上,我将不同意CommonsWare。 I am using the android.hardware.Camera with my app and testing with a Samsung Galaxy S4 running Lollipop. 我将android.hardware.Camera与我的应用程序一起使用,并与运行Lollipop的Samsung Galaxy S4进行了测试。 It seems the problem is that onCreate is called before onActivityResult when running the app on Samsung Lollipop. 似乎问题是在Samsung Lollipop上运行应用程序时,在onActivityResult之前调用了onCreate。

My suggestion is to set the max target in your app to 20 (Android 4.4) until Samsung sorts this out. 我的建议是将应用程序中的最大目标设置为20(Android 4.4),直到三星将其解决为止。 It is a Samsung issue. 这是三星的问题。

 android:maxSdkVersion="20"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM