I have made an app for Android (target SDK 27) that uses 2 modules, one made by me and another one has been imported. This last module requires the use of CAMERA and EXTERNAL STORAGE (read/write), therefore the manifest file includes the necessary lines.
Also, I check and ask during runtime for these permissions and user is able to grant or not access. When I go to "App settings", both CAMERA and STORAGE are turned on. Everything seems fine.
However, the app crashes after taking a picture with the camera or selecting one from the gallery.
On the other side, If I grant these permissions manually on the App settings, everything works fine!
Any idea?
Manifest permissions
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
TEST Thread continuously checking for permissions before Activity execution
private void checkPermissions(){
new Thread(new Runnable() {
@Override
public void run() {
while(!hasStorageAccess()){
requestStoragePermission();
}
while (!hasCameraAccess()) {
requestCameraPermission();
}
init();
}
}).start();
}
Runtime permissions (Work perfectly on other apps made by me)
private boolean hasCameraAccess() {
return ContextCompat.checkSelfPermission(ScanActivity.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
}
private void requestCameraPermission() {
ActivityCompat.requestPermissions(ScanActivity.this, new String[]{Manifest.permission.CAMERA}, PERMISSIONS_REQUEST_USE_CAMERA);
}
private boolean hasStorageAccess() {
return ContextCompat.checkSelfPermission(ScanActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
}
private void requestStoragePermission() {
ActivityCompat.requestPermissions(ScanActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_USE_STORAGE);
}