Reputation: 305
I've been working on an Android App. It does recording and writes to the local storage area. Here are the permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
And in the middle of debugging I lost the permissions on the tablet itself. I had to go to Settings->Applications->(my app)->App Permissions and turn them on myself. Both Microphone and Storage had their sliders set to off.
While I am up and running now, I would love to know how this might have happened so I can prevent it from happening again.
Any clues as to where I should look?
Thank you,
Upvotes: 0
Views: 558
Reputation: 8149
Runtime permissions demo.
public class MyDevIDS extends AppCompatActivity {
private static final int REQUEST_RUNTIME_PERMISSION = 123;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (CheckPermission(MyDevIDS.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// you have permission go ahead
createApplicationFolder();
} else {
// you do not have permission go request runtime permissions
RequestPermission(MyDevIDS.this, Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_RUNTIME_PERMISSION);
}
}
@Override
public void onRequestPermissionsResult(int permsRequestCode, String[] permissions, int[] grantResults) {
switch (permsRequestCode) {
case REQUEST_RUNTIME_PERMISSION: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// you have permission go ahead
createApplicationFolder();
} else {
// you do not have permission show toast.
}
return;
}
}
}
public void RequestPermission(Activity thisActivity, String Permission, int Code) {
if (ContextCompat.checkSelfPermission(thisActivity,
Permission)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Permission)) {
} else {
ActivityCompat.requestPermissions(thisActivity,
new String[]{Permission},
Code);
}
}
}
public boolean CheckPermission(Context context, String Permission) {
if (ContextCompat.checkSelfPermission(context,
Permission) == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
}
}
Upvotes: 1
Reputation: 2137
On Android 6+, some permissions like Storage aren't granted without explicit request at runtime.
If you uninstall and reinstall the app or simply clear the app data, the permissions be revoked. That may explain your situation.
Upvotes: 0