Android 6+ Permissions #4
This commit is contained in:
parent
1967602c70
commit
33d783e9b0
1 changed files with 24 additions and 15 deletions
|
@ -52,7 +52,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
checkEula();
|
checkEula();
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, CASE_STORAGE);
|
askForPermission(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE}, CASE_STORAGE);
|
||||||
}
|
}
|
||||||
if (Config.logFunctionCalls)
|
if (Config.logFunctionCalls)
|
||||||
log.debug("onCreate");
|
log.debug("onCreate");
|
||||||
|
@ -197,14 +198,20 @@ public class MainActivity extends AppCompatActivity {
|
||||||
SharedPreferences smssettings = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences smssettings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
if (smssettings.getBoolean("smscommunicator_remotecommandsallowed", false)) {
|
if (smssettings.getBoolean("smscommunicator_remotecommandsallowed", false)) {
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
askForPermission(Manifest.permission.RECEIVE_SMS, CASE_SMS);
|
askForPermission(new String[]{Manifest.permission.RECEIVE_SMS,
|
||||||
|
Manifest.permission.SEND_SMS,
|
||||||
|
Manifest.permission.RECEIVE_MMS}, CASE_SMS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void askForPermission(String permission, Integer requestCode) {
|
private void askForPermission(String[] permission, Integer requestCode) {
|
||||||
if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
|
boolean test = false;
|
||||||
ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);
|
for (int i=0; i < permission.length; i++) {
|
||||||
|
test = test || (ContextCompat.checkSelfPermission(this, permission[i]) != PackageManager.PERMISSION_GRANTED);
|
||||||
|
}
|
||||||
|
if (test) {
|
||||||
|
ActivityCompat.requestPermissions(this, permission, requestCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +219,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
if(ActivityCompat.checkSelfPermission(this, permissions[0]) == PackageManager.PERMISSION_GRANTED){
|
if(ActivityCompat.checkSelfPermission(this, permissions[0]) == PackageManager.PERMISSION_GRANTED){
|
||||||
|
if(permissions.length != 0){
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case 1:
|
case 1:
|
||||||
//show dialog after permission is granted
|
//show dialog after permission is granted
|
||||||
|
@ -225,4 +233,5 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue