Adding files for Android 6 Marshmallow compatibility and 64 bit devices, such as the Nexus 5x.

Fixes issue # 50 https://github.com/tjwoon/csZBar/issues/50
This commit is contained in:
Jacob Hargrave 2016-02-29 14:08:53 -05:00 committed by Daniel Cousens
parent c51cfec6ff
commit 86f2ba77f7
4 changed files with 108 additions and 64 deletions

View File

@ -5,6 +5,7 @@ import java.lang.RuntimeException;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
@ -16,6 +17,8 @@ import android.hardware.Camera.PreviewCallback;
import android.hardware.Camera.AutoFocusCallback; import android.hardware.Camera.AutoFocusCallback;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log; import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
@ -24,6 +27,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.TextView; import android.widget.TextView;
import android.content.pm.PackageManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -52,7 +56,7 @@ implements SurfaceHolder.Callback {
public static final String EXTRA_QRVALUE = "qrValue"; public static final String EXTRA_QRVALUE = "qrValue";
public static final String EXTRA_PARAMS = "params"; public static final String EXTRA_PARAMS = "params";
public static final int RESULT_ERROR = RESULT_FIRST_USER + 1; public static final int RESULT_ERROR = RESULT_FIRST_USER + 1;
private static final int CAMERA_PERMISSION_REQUEST = 1;
// State ----------------------------------------------------------- // State -----------------------------------------------------------
private Camera camera; private Camera camera;
@ -82,10 +86,47 @@ implements SurfaceHolder.Callback {
// Activity Lifecycle ---------------------------------------------- // Activity Lifecycle ----------------------------------------------
@Override @Override
public void onCreate (Bundle savedInstanceState) public void onCreate (Bundle savedInstanceState) {
{
int permissionCheck = ContextCompat.checkSelfPermission(this.getBaseContext(), Manifest.permission.CAMERA);
if(permissionCheck == PackageManager.PERMISSION_GRANTED){
setUpCamera();
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA},
CAMERA_PERMISSION_REQUEST);
}
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
}
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case CAMERA_PERMISSION_REQUEST: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
setUpCamera();
} else {
onBackPressed();
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
private void setUpCamera() {
// If request is cancelled, the result arrays are empty.
// Get parameters from JS // Get parameters from JS
Intent startIntent = getIntent(); Intent startIntent = getIntent();
String paramStr = startIntent.getStringExtra(EXTRA_PARAMS); String paramStr = startIntent.getStringExtra(EXTRA_PARAMS);
@ -149,6 +190,7 @@ implements SurfaceHolder.Callback {
findViewById(getResourceId("id/csZbarScannerSight")).bringToFront(); findViewById(getResourceId("id/csZbarScannerSight")).bringToFront();
scannerView.requestLayout(); scannerView.requestLayout();
scannerView.invalidate(); scannerView.invalidate();
} }
@Override @Override
@ -172,10 +214,10 @@ implements SurfaceHolder.Callback {
if(camera == null) throw new Exception ("Error: No suitable camera found."); if(camera == null) throw new Exception ("Error: No suitable camera found.");
} catch (RuntimeException e) { } catch (RuntimeException e) {
die("Error: Could not open the camera."); //die("Error: Could not open the camera.");
return; return;
} catch (Exception e) { } catch (Exception e) {
die(e.getMessage()); // die(e.getMessage());
return; return;
} }
} }
@ -190,7 +232,7 @@ implements SurfaceHolder.Callback {
@Override @Override
public void onDestroy () public void onDestroy ()
{ {
scanner.destroy(); if(scanner != null) scanner.destroy();
super.onDestroy(); super.onDestroy();
} }

Binary file not shown.

Binary file not shown.

View File

@ -51,6 +51,8 @@
<source-file src="android/libs/armeabi/libzbarjni.so" target-dir="libs/armeabi" /> <source-file src="android/libs/armeabi/libzbarjni.so" target-dir="libs/armeabi" />
<source-file src="android/libs/armeabi-v7a/libiconv.so" target-dir="libs/armeabi-v7a" /> <source-file src="android/libs/armeabi-v7a/libiconv.so" target-dir="libs/armeabi-v7a" />
<source-file src="android/libs/armeabi-v7a/libzbarjni.so" target-dir="libs/armeabi-v7a" /> <source-file src="android/libs/armeabi-v7a/libzbarjni.so" target-dir="libs/armeabi-v7a" />
<source-file src="android/libs/arm64-v8a/libiconv.so" target-dir="libs/arm64-v8a" />
<source-file src="android/libs/arm64-v8a/libzbarjni.so" target-dir="libs/arm64-v8a" />s
<source-file src="android/libs/x86/libiconv.so" target-dir="libs/x86" /> <source-file src="android/libs/x86/libiconv.so" target-dir="libs/x86" />
<source-file src="android/libs/x86/libzbarjni.so" target-dir="libs/x86" /> <source-file src="android/libs/x86/libzbarjni.so" target-dir="libs/x86" />
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable"/> <source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable"/>