Android N Developer Preview: Camera support takes a third value - android

I have a Nexus 6P. I'm investigating why OpenCamera has stopped working on Android N Developer Preview (I'm not a developer, just a user). I have found the following piece of code that might be causing the problem: CameraControllerManager2.java:62
I created a new Android project, and added the following function:
...
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata;
...
public class MainActivity extends AppCompatActivity {
private String TAG = "MainActivity";
...
public void test(int cameraId) {
CameraManager manager = (CameraManager)this.getSystemService(Context.CAMERA_SERVICE);
try {
String cameraIdS = manager.getCameraIdList()[cameraId];
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraIdS);
int support = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
Log.d(TAG, "Camera support: " + support);
}
catch (CameraAccessException e) {
e.printStackTrace();
}
}
...
}
Calling test(0), the console output on my device is:
04-22 15:16:54.263 11578-11578/test.myapplication D/MainActivity: Camera support: 3
When I look up the possible values of support (docs), they must be 0, 1 or 2, but how is support taking the value of 3? Is it supposed to be a bitmask or something worse is happening?

You are looking at the docs for the shipping version of Android. At the present time, Android N is in a developer preview, and the docs are elsewhere.
There is a new INFO_SUPPORTED_HARDWARE_LEVEL_3 value for that characteristic, described as:
...devices additionally support YUV reprocessing and RAW image capture, along with additional output stream configurations.

Related

How to turn on the torch/flashlight with GooglePlay Services Vision API Xamarin Android

I have been trying to implement the flashlight/torch feature of the camera using the GooglePlay Services Vision API (using Nuget from Visual Studio) for the past few days without success. I have noticed that there is a GitHub implementation of this API which has such functionality but that is only available to Java users.
I was wondering if there is anything related to C# Xamarin users.
The Camera object is not made available on this API therefore I am not able to alter the Camera parameters needed to activate the flashlight.
I would like to be sure if that functionality is not available so I don't waste more time over this. It just might be the case that the Xamarin developers have not attended to this functionality and they might in a near future.
UPDATE
https://github.com/googlesamples/android-vision/blob/master/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeCaptureActivity.java
In there you can see that on line 214 we have such method call:
mCameraSource = builder.setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null).build();
SetFlashMode is not a method of the CameraSource in Nuget, but it is on the GitHub (open source version).
Xamarin Vision Library Didn't expose the method to set Flash Mode.
WorkAround.
Using Reflection. You can get the Camera Object from CameraSouce and add the flash parameter then set the updated parameters to the camera.
This should be called after surfaceview has been created
Code
public Camera getCameraObject (CameraSource _camSource)
{
Field [] cFields = _camSource.Class.GetDeclaredFields ();
Camera _cam = null;
try {
foreach (Field item in cFields) {
if (item.Name.Equals ("zzbNN")) {
Console.WriteLine ("Camera");
item.Accessible = true;
try {
_cam = (Camera)item.Get (_camSource);
} catch (Exception e) {
Logger.LogException (this, e);
}
}
}
} catch (Exception e) {
Logger.LogException (this, e);
}
return _cam;
}
public void setFlash (bool isEnable)
{
try {
isTorch = !isEnable;
var _cam = getCameraObject (mCameraSource);
if (_cam == null) return;
var _pareMeters = _cam.GetParameters ();
var _listOfSuppo = _cam.GetParameters ().SupportedFlashModes;
_pareMeters.FlashMode = isTorch ? _listOfSuppo [0] : _listOfSuppo [3];
_cam.SetParameters (_pareMeters);
} catch (Exception e) {
Logger.LogException (this, e);
}
}
Basically, anything you can do with Android can be done with Xamarin.Android. All the underlying APIs area available.
Since you have existing Java code, you can create a binding project that enables you to call the code from your Xamarin.Android project. Here's a good article on how to get started: Binding a Java Library
On the other hand, I don't think you need a library to do what you want to. If you only want torch/flashlight functionality, you just need to adapt the Java code from this answer to work in Xamarin.Android with C#.

Android: PackageManager.getSystemAvailableFeatures() is not working as expected on Nexus9

I am trying to get all the available system features on my Nexus9 device using PackageManager.getSystemAvailableFeatures().
From Android 5.0 Lollipop, Google introduced new camera APIs (camera2). I think Nexus9 is using Camera2 APIs.
When I am running this API on Nexus9 device it is not listing camera2 APIs features like:
android.hardware.camera.level.full
android.hardware.camera.capability.manual_post_processing
android.hardware.camera.capability.manual_sensor
android.hardware.camera.capability.raw
I am using below code to get all the available features:
public final static boolean isFeatureAvailable(Context context, String feature) {
final PackageManager packageManager = context.getPackageManager();
final FeatureInfo[] featuresList = packageManager.getSystemAvailableFeatures();
for (FeatureInfo f : featuresList) {
if (f.name != null && f.name.equals(feature)) {
return true;
}
}
return false;
}
Questions:
Is Nexus9 using & having camera2 API features?
If answer is yes for above question, then Why it is not listing these system level features? I am doing something wrong?
Thanks for your comments in advance!
Is Nexus9 using & having camera2 API features?
Yes. All Android Lollipop devices and newer have the camera2 APIs.
If answer is yes for above question, then Why it is not listing these system level features?
Supported APIs are usually not included in the system features list. Most system features are related to things that can vary from device to device and are usually related to hardware features (e.g. sensors, bluetooth, NFC, etc) or system-wide software support (e.g. backup, device management, multi-user, etc). There's a list of all supported capabilities here.
I am doing something wrong?
According to the docs, the recommended way to check if the camera2 APIs exist is by requesting the camera service via:
CameraManager cameraManager = (CameraManager) getSystemService("camera");
Basically this method returns null if the camera2 APIs aren't available, either because the version of Android is too old (sdkVersion < 21) or because they've been removed from the system (e.g. via a custom ROM).
Finally I was able to get answers to my questions.
Is Nexus9 using & having camera2 API features?
Ans: Yes Nexus9 is having and using Camera2 APIs. It has LIMITED supported hardware level and has capabilities: BACKWARD_COMPATIBLE and MANUAL_SENSOR
If answer is yes for above question, then Why it is not listing these system level features? I am doing something wrong?
Ans: Because using above code I am listing features not capabilities. To list down the capabilities I used below code:
Activity activity = getActivity();
CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
try {
for (String cameraId : manager.getCameraIdList()) {
CameraCharacteristics characteristics
= manager.getCameraCharacteristics(cameraId);
if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL) {
Log.d("Camera2 SUPPORTED_HARDWARE_LEVEL: ", "FULL");
} else if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
Log.d("Camera2 SUPPORTED_HARDWARE_LEVEL: ", "LEGACY");
} else if(characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED) {
Log.d("Camera2 SUPPORTED_HARDWARE_LEVEL: ", "LIMITED");
}
StringBuilder stringBuilder = new StringBuilder();
for (int i=0; i<characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES).length; i++) {
if(characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)[i] ==CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE) {
stringBuilder.append("BACKWARD_COMPATIBLE" + " ");
} else if (characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)[i] ==CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING) {
stringBuilder.append("MANUAL_POST_PROCESSING" + " ");
} else if(characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)[i] ==CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR) {
stringBuilder.append("MANUAL_SENSOR" + " ");
} else if (characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)[i] ==CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW) {
stringBuilder.append("RAW" + " ");
}
}
Log.d("Camera2: ", stringBuilder.toString());

Simple flash video loop play (played on android) always crash after a few hours

Why is my flash-based video player on android always crash after a few hours of play?
I'm writing a flash-based Android App. The only thing that native android part do using webview to load a flash swf. The swf acted as the container for all module (which all written in flash as3). One of the module is a simple video module which loop play a set of video playlist forever.
I've considered memory leak, but after printing memory usage (using flash's System.totalMemory), the result is always around 12MB to 14MB (which seems normal for two videos). I've test the flash using both webview and other third party swf player for android (such as "Swf Player" and "Smart SWF Player"), all results in crash after a few hours.
The as3 code is simple and I can't see any possible cause for this. Here is my main class:
import flash.display.MovieClip;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
public class simpleVid extends MovieClip {
private var video:Video;
private var nc:NetConnection;
private var ns:NetStream;
private var uri:Array = new Array("vid1.flv", "vid2.flv");
private var counter:int = 0;
public function simpleVid() {
// constructor code
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
video = new Video();
video.attachNetStream(ns);
ns.client = {onMetaData:videoReady, NetStatusEvent:onStatusEvent};
ns.addEventListener(NetStatusEvent.NET_STATUS, onStatusEvent);
ns.play(uri[counter]);
stage.addChild(video);
counter++;
counter = counter % 2;
}
public function videoReady(item:Object){
video.width = 1280;
video.height = 720;
}
public function onStatusEvent(event:NetStatusEvent):void{
if (event.info.code == "NetStream.Play.Stop") {
ns.play(uri[counter]);
counter++;
counter = counter % 2;
}
}
}
Is there is anything I missed or I did wrong in this code?
Thanks in advance.
The problem "mysteriously" disappeared after I switch to AIR instead of flash.
No code is changed, I only changed the release setting from Flash player to air for android.
Now it can run continuously for several days without problem.

android ExifInterface platform 1.5, 1.6 [duplicate]

Is there any 3rd part api for android to read exif tags from image which support api level starting from 1.5.
The metadata extraction library by Drew Noakes works well for extracting EXIF tags on earlier Android platform versions, with a slight modification. I am using it on Android 1.6 to extract tags from JPEG images.
NOTE: Newer versions of metadata-extractor work directly on Android without modification.
You will need to download and build the source code yourself, and package it with your app. (I'm using release 2.3.1.) Make the following changes to com.drew.imaging.jpeg.JpegMetadataReader:
Remove the following import statement:
import com.sun.image.codec.jpeg.JPEGDecodeParam;
Delete the following method (which you won't need on Android):
public static Metadata readMetadata(JPEGDecodeParam decodeParam) { ... }
Remove the com.drew.metadata.SampleUsage class, which references the method deleted above. Also remove all of the test packages.
That's all there is to it. Here's an example of using the JpegMetadataReader to extract a date-time tag from a JPEG image stored on the SD card:
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifDirectory;
// other imports and class definition removed for brevity
public static Date extractExifDateTime(String imagePath)
{
Log.d("exif", "Attempting to extract EXIF date/time from image at " + imagePath);
Date datetime = new Date(0); // or initialize to null, if you prefer
try
{
Metadata metadata = JpegMetadataReader.readMetadata(new File(imagePath));
Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
// these are listed in order of preference
int[] datetimeTags = new int[] { ExifDirectory.TAG_DATETIME_ORIGINAL,
ExifDirectory.TAG_DATETIME,
ExifDirectory.TAG_DATETIME_DIGITIZED };
int datetimeTag = -1;
for (int tag : datetimeTags)
{
if (exifDirectory.containsTag(tag))
{
datetimeTag = tag;
break;
}
}
if (datetimeTag != -1)
{
Log.d("exif", "Using tag " + exifDirectory.getTagName(datetimeTag) + " for timestamp");
SimpleDateFormat exifDatetimeFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
datetime = exifDatetimeFormat.parse(exifDirectory.getString(datetimeTag));
}
else
{
Log.d("exif", "No date/time tags were found");
}
}
catch (Exception e)
{
Log.w("exif", "Unable to extract EXIF metadata from image at " + imagePath, e);
}
return datetime;
}
For what it worth, did you try to use the native ExifInterface class ?
http://developer.android.com/reference/android/media/ExifInterface.html
Should be must faster than using a 3rd party library ;)

android image exif reader 3rd party api

Is there any 3rd part api for android to read exif tags from image which support api level starting from 1.5.
The metadata extraction library by Drew Noakes works well for extracting EXIF tags on earlier Android platform versions, with a slight modification. I am using it on Android 1.6 to extract tags from JPEG images.
NOTE: Newer versions of metadata-extractor work directly on Android without modification.
You will need to download and build the source code yourself, and package it with your app. (I'm using release 2.3.1.) Make the following changes to com.drew.imaging.jpeg.JpegMetadataReader:
Remove the following import statement:
import com.sun.image.codec.jpeg.JPEGDecodeParam;
Delete the following method (which you won't need on Android):
public static Metadata readMetadata(JPEGDecodeParam decodeParam) { ... }
Remove the com.drew.metadata.SampleUsage class, which references the method deleted above. Also remove all of the test packages.
That's all there is to it. Here's an example of using the JpegMetadataReader to extract a date-time tag from a JPEG image stored on the SD card:
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifDirectory;
// other imports and class definition removed for brevity
public static Date extractExifDateTime(String imagePath)
{
Log.d("exif", "Attempting to extract EXIF date/time from image at " + imagePath);
Date datetime = new Date(0); // or initialize to null, if you prefer
try
{
Metadata metadata = JpegMetadataReader.readMetadata(new File(imagePath));
Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
// these are listed in order of preference
int[] datetimeTags = new int[] { ExifDirectory.TAG_DATETIME_ORIGINAL,
ExifDirectory.TAG_DATETIME,
ExifDirectory.TAG_DATETIME_DIGITIZED };
int datetimeTag = -1;
for (int tag : datetimeTags)
{
if (exifDirectory.containsTag(tag))
{
datetimeTag = tag;
break;
}
}
if (datetimeTag != -1)
{
Log.d("exif", "Using tag " + exifDirectory.getTagName(datetimeTag) + " for timestamp");
SimpleDateFormat exifDatetimeFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
datetime = exifDatetimeFormat.parse(exifDirectory.getString(datetimeTag));
}
else
{
Log.d("exif", "No date/time tags were found");
}
}
catch (Exception e)
{
Log.w("exif", "Unable to extract EXIF metadata from image at " + imagePath, e);
}
return datetime;
}
For what it worth, did you try to use the native ExifInterface class ?
http://developer.android.com/reference/android/media/ExifInterface.html
Should be must faster than using a 3rd party library ;)

Categories

Resources