0

I am working with some camera-related features. For some of the devices (like a smart glass called Vuzix) the camera is flipped upside down, so when passing some attributes I need to do ROTATE.180 while for the others it is not flipped so I just need to pass ROTATE.NONE; I want to know if there is any way I could get the running device name/camera flipped or not in an if statement like (if device.name==Vuzix) or something like (if camera.orientation==reversed). Right now I have to manually change before running on each device.

Ryan M
  • 18,333
  • 31
  • 67
  • 74

2 Answers2

0

Yeah Sure, you can easily detect on what device your code is running on. See this link : How to detect a mobile device manufacturer and model programmatically in Android?

You can get Device name and Manufacturer as follows :

String deviceName = android.os.Build.MODEL;
String deviceMan = android.os.Build.MANUFACTURER;
Sainita
  • 332
  • 1
  • 4
  • 16
0

You can certainly put in a check for the manufacturer, but it is not the most robust solution. Vuzix glasses have a sensor orientation is upside-down compared to many other vendors, but there are others that use this same mounting besides Vuzix.

Luckily on Vuzix products, the camera characteristics reflect this, so you can use the sample code published by Android Developer Documentation. You query the Window Manager for the display orientation, and the camera Characteristics to find the sensor mounting. Then you can use the same code no matter what device you are using.

 public static void setCameraDisplayOrientation(Activity activity,
     int cameraId, android.hardware.Camera camera) {
 android.hardware.Camera.CameraInfo info =
         new android.hardware.Camera.CameraInfo();
 android.hardware.Camera.getCameraInfo(cameraId, info);
 int rotation = activity.getWindowManager().getDefaultDisplay()
         .getRotation();
 int degrees = 0;
 switch (rotation) {
     case Surface.ROTATION_0: degrees = 0; break;
     case Surface.ROTATION_90: degrees = 90; break;
     case Surface.ROTATION_180: degrees = 180; break;
     case Surface.ROTATION_270: degrees = 270; break;
 }

 int result;
 if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
     result = (info.orientation + degrees) % 360;
     result = (360 - result) % 360;  // compensate the mirror
 } else {  // back-facing
     result = (info.orientation - degrees + 360) % 360;
 }
 camera.setDisplayOrientation(result);

}

Brent K.
  • 927
  • 1
  • 11
  • 16