diff --git a/app/build.gradle b/app/build.gradle
index ef2f4829..2040fcde 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -33,7 +33,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar'
- compile 'com.google.zxing:core:3.2.0'
+ compile 'com.google.zxing:core:3.2.1'
compile 'commons-codec:commons-codec:1.5'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
diff --git a/app/src/main/java/net/bierbaumer/otp_authenticator/MainActivity.java b/app/src/main/java/net/bierbaumer/otp_authenticator/MainActivity.java
index fb86b8cb..0ea4f9fc 100644
--- a/app/src/main/java/net/bierbaumer/otp_authenticator/MainActivity.java
+++ b/app/src/main/java/net/bierbaumer/otp_authenticator/MainActivity.java
@@ -1,14 +1,19 @@
package net.bierbaumer.otp_authenticator;
+import android.Manifest;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
+import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.ActionMode;
@@ -38,6 +43,49 @@ public class MainActivity extends AppCompatActivity implements ActionMode.Callb
private Handler handler;
private Runnable handlerTask;
+ private static final int PERMISSIONS_REQUEST_CAMERA = 42;
+
+ private void doScanQRCode(){
+ new IntentIntegrator(MainActivity.this)
+ .setCaptureActivity(CaptureActivityAnyOrientation.class)
+ .setOrientationLocked(false)
+ .initiateScan();
+ }
+
+ private void scanQRCode(){
+ // check Android 6 permission
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
+ doScanQRCode();
+ } else {
+ ActivityCompat.requestPermissions(this,
+ new String[]{Manifest.permission.CAMERA}, PERMISSIONS_REQUEST_CAMERA);
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
+ if(requestCode == PERMISSIONS_REQUEST_CAMERA) {
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ // permission was granted
+ doScanQRCode();
+ } else {
+ Snackbar.make(fab, R.string.msg_camera_permission, Snackbar.LENGTH_LONG).setCallback(new Snackbar.Callback() {
+ @Override
+ public void onDismissed(Snackbar snackbar, int event) {
+ super.onDismissed(snackbar, event);
+
+ if (entries.isEmpty()) {
+ showNoAccount();
+ }
+ }
+ }).show();
+ }
+ }
+ else {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ }
+ }
+
private Entry nextSelection = null;
private void showNoAccount(){
Snackbar noAccountSnackbar = Snackbar.make(fab, R.string.no_accounts, Snackbar.LENGTH_INDEFINITE)
@@ -50,13 +98,6 @@ public class MainActivity extends AppCompatActivity implements ActionMode.Callb
noAccountSnackbar.show();
}
- private void scanQRCode(){
- new IntentIntegrator(MainActivity.this)
- .setCaptureActivity(CaptureActivityAnyOrientation.class)
- .setOrientationLocked(false)
- .initiateScan();
- }
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f5c38b7e..4eef8a54 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -16,4 +16,5 @@
Remove
Rename
"Remove "
+ Camera permission not granted