SMS permission crashfix
This commit is contained in:
parent
33d783e9b0
commit
ff29a795db
1 changed files with 37 additions and 11 deletions
|
@ -41,8 +41,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private static KeepAliveReceiver keepAliveReceiver;
|
private static KeepAliveReceiver keepAliveReceiver;
|
||||||
|
|
||||||
static final Integer CASE_STORAGE = 0x1;
|
static final int CASE_STORAGE = 0x1;
|
||||||
static final Integer CASE_SMS = 0x2;
|
static final int CASE_SMS = 0x2;
|
||||||
|
|
||||||
|
private boolean askForSMS = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -195,12 +197,36 @@ public class MainActivity extends AppCompatActivity {
|
||||||
//check for sms permission if enable in prefernces
|
//check for sms permission if enable in prefernces
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||||
SharedPreferences smssettings = PreferenceManager.getDefaultSharedPreferences(this);
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
if (smssettings.getBoolean("smscommunicator_remotecommandsallowed", false)) {
|
SharedPreferences smssettings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
synchronized (this){
|
||||||
askForPermission(new String[]{Manifest.permission.RECEIVE_SMS,
|
if (smssettings.getBoolean("smscommunicator_remotecommandsallowed", false)) {
|
||||||
Manifest.permission.SEND_SMS,
|
setAskForSMS();
|
||||||
Manifest.permission.RECEIVE_MMS}, CASE_SMS);
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void setAskForSMS() {
|
||||||
|
askForSMS = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume(){
|
||||||
|
super.onResume();
|
||||||
|
askForSMSPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void askForSMSPermissions(){
|
||||||
|
if (askForSMS) { //only when settings were changed an MainActivity resumes.
|
||||||
|
askForSMS = false;
|
||||||
|
SharedPreferences smssettings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
if (smssettings.getBoolean("smscommunicator_remotecommandsallowed", false)) {
|
||||||
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
|
askForPermission(new String[]{Manifest.permission.RECEIVE_SMS,
|
||||||
|
Manifest.permission.SEND_SMS,
|
||||||
|
Manifest.permission.RECEIVE_MMS}, CASE_SMS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,17 +247,17 @@ public class MainActivity extends AppCompatActivity {
|
||||||
if(ActivityCompat.checkSelfPermission(this, permissions[0]) == PackageManager.PERMISSION_GRANTED){
|
if(ActivityCompat.checkSelfPermission(this, permissions[0]) == PackageManager.PERMISSION_GRANTED){
|
||||||
if(permissions.length != 0){
|
if(permissions.length != 0){
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case 1:
|
case CASE_STORAGE:
|
||||||
//show dialog after permission is granted
|
//show dialog after permission is granted
|
||||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||||
alert.setMessage(R.string.alert_dialog_storage_permission_text);
|
alert.setMessage(R.string.alert_dialog_storage_permission_text);
|
||||||
alert.setPositiveButton(R.string.alert_dialog_positive_button,null);
|
alert.setPositiveButton(R.string.alert_dialog_positive_button,null);
|
||||||
alert.show();
|
alert.show();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case CASE_SMS:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue