Merge pull request #158 from alexbakker/fix-150

Get external storage read permissions before selecting an image to scan
pull/170/head
Michael Schättgen 6 years ago committed by GitHub
commit 86c4011797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -65,6 +65,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
// permission request codes // permission request codes
private static final int CODE_PERM_CAMERA = 0; private static final int CODE_PERM_CAMERA = 0;
private static final int CODE_PERM_READ_STORAGE = 1;
private AegisApplication _app; private AegisApplication _app;
private DatabaseManager _db; private DatabaseManager _db;
@ -106,12 +107,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
}); });
findViewById(R.id.fab_scan_image).setOnClickListener(view -> { findViewById(R.id.fab_scan_image).setOnClickListener(view -> {
_fabMenu.collapse(); _fabMenu.collapse();
startScanImageActivity();
Intent galleryIntent = new Intent(Intent.ACTION_PICK);
galleryIntent.setDataAndType(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*");
Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.select_picture));
startActivityForResult(Intent.createChooser(chooserIntent, getString(R.string.select_picture)), CODE_SCAN_IMAGE);
}); });
findViewById(R.id.fab_scan).setOnClickListener(view -> { findViewById(R.id.fab_scan).setOnClickListener(view -> {
_fabMenu.collapse(); _fabMenu.collapse();
@ -195,6 +191,9 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
case CODE_PERM_CAMERA: case CODE_PERM_CAMERA:
startScanActivity(); startScanActivity();
break; break;
case CODE_PERM_READ_STORAGE:
startScanImageActivity();
break;
} }
} }
@ -371,6 +370,18 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
startActivityForResult(scannerActivity, CODE_SCAN); startActivityForResult(scannerActivity, CODE_SCAN);
} }
private void startScanImageActivity() {
if (!PermissionHelper.request(this, CODE_PERM_READ_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)) {
return;
}
Intent galleryIntent = new Intent(Intent.ACTION_PICK);
galleryIntent.setDataAndType(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*");
Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.select_picture));
startActivityForResult(Intent.createChooser(chooserIntent, getString(R.string.select_picture)), CODE_SCAN_IMAGE);
}
private void doShortcutActions() { private void doShortcutActions() {
Intent intent = getIntent(); Intent intent = getIntent();
String action = intent.getStringExtra("action"); String action = intent.getStringExtra("action");

Loading…
Cancel
Save