prompt user to open permission when using camera
MODIFY
bither-android/res/values/strings.xml
bither-android/res/values/strings.xml
<string name="bitpie_scan_unsigned_transaction_title">Scan QR Code on Bitpie</string>
<string name="bitpie_scan_message_title">Scan QR Code on Bitpie</string>
+
+ <string name="permissions_no_grant">Please go to Phone Setting->Apps->Bither->Permission to switch on relevant permissions, otherwise the function cannot be used.</string>
+
</resources>

MODIFY
bither-android/src/net/bither/BitherSetting.java
bither-android/src/net/bither/BitherSetting.java
@@ -48,6 +48,7 @@ public class BitherSetting {
public static final int REQUEST_CODE_IMAGE = 1007;
public static final int REQUEST_CODE_CAMERA = 1008;
public static final int REQUEST_CODE_CROP_IMAGE = 1009;
+ public static final int REQUEST_CODE_PERMISSION_CAMERA = 1010;
public static final long LAST_USAGE_THRESHOLD_JUST_MS = DateUtils.HOUR_IN_MILLIS;
public static final long LAST_USAGE_THRESHOLD_RECENTLY_MS = 2 * DateUtils.DAY_IN_MILLIS;

MODIFY
bither-android/src/net/bither/qrcode/ScanActivity.java
bither-android/src/net/bither/qrcode/ScanActivity.java
@@ -18,6 +18,7 @@ package net.bither.qrcode;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
@@ -33,6 +34,7 @@ import android.os.HandlerThread;
import android.os.Process;
import android.os.Vibrator;
import android.provider.MediaStore;
+import android.provider.Settings;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
@@ -57,15 +59,17 @@ import com.google.zxing.ResultPointCallback;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
+import net.bither.BitherSetting;
import net.bither.R;
-import net.bither.bitherj.core.SplitCoin;
import net.bither.camera.CameraManager;
import net.bither.ui.base.BaseActivity;
import net.bither.ui.base.DropdownMessage;
import net.bither.ui.base.ScannerView;
+import net.bither.ui.base.dialog.DialogConfirmTask;
import net.bither.ui.base.dialog.DialogProgress;
import net.bither.util.FileUtil;
import net.bither.util.ImageManageUtil;
+import net.bither.util.PermissionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,8 +79,6 @@ import java.io.IOException;
import java.util.EnumMap;
import java.util.Map;
-import static net.bither.activity.hot.HotAdvanceActivity.SplitCoinKey;
-
public class ScanActivity extends BaseActivity implements SurfaceHolder.Callback,
CompoundButton.OnCheckedChangeListener {
public static final String INTENT_EXTRA_RESULT = "result";
@@ -146,8 +148,37 @@ public class ScanActivity extends BaseActivity implements SurfaceHolder.Callback
@Override
public void surfaceCreated(final SurfaceHolder holder) {
+ if (PermissionUtil.isCameraPermission(this, BitherSetting.REQUEST_CODE_PERMISSION_CAMERA)) {
cameraHandler.post(openRunnable);
}
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ switch (requestCode) {
+ case BitherSetting.REQUEST_CODE_PERMISSION_CAMERA:
+ if (grantResults != null && grantResults.length > 0) {
+ if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
+ DialogConfirmTask dialogConfirmTask = new DialogConfirmTask(
+ this, getString(R.string.permissions_no_grant), new Runnable() {
+ @Override
+ public void run() {
+ Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
+ Uri uri = Uri.fromParts("package", getPackageName(), null);
+ intent.setData(uri);
+ startActivity(intent);
+ }
+ });
+ dialogConfirmTask.show();
+ } else {
+ openRunnable.run();
+ }
+ }
+ default:
+ break;
+ }
+ }
@Override
public void surfaceDestroyed(final SurfaceHolder holder) {

ADD
bither-android/src/net/bither/util/PermissionUtil.java
+package net.bither.util;
+
+import android.Manifest;
+import android.app.Activity;
+import android.content.pm.PackageManager;
+import android.os.Build;
+
+public class PermissionUtil {
+
+ private static String PERMISSION_CAMERA = Manifest.permission.CAMERA;
+
+ public static boolean isCameraPermission(Activity activity, int requestCode) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (activity.checkSelfPermission(PERMISSION_CAMERA) != PackageManager.PERMISSION_GRANTED) {
+ activity.requestPermissions(new String[]{PERMISSION_CAMERA}, requestCode);
+ return false;
+ }
+ }
+ return true;
+ }
+
+}

prompt user to open permission when using camera