add permission exception for android < Marshmallow

This commit is contained in:
Christian Schneppe 2016-06-12 21:13:09 +02:00
parent ab2b46fd72
commit 232de4436c
2 changed files with 18 additions and 12 deletions

View file

@ -126,6 +126,8 @@ public class ConversationActivity extends XmppActivity
private AtomicBoolean mRedirected = new AtomicBoolean(false);
private Pair<Integer, Intent> mPostponedActivityResult;
long FirstStartTime = 0;
@SuppressLint("NewApi")
private static List<Uri> extractUriFromIntent(final Intent intent) {
List<Uri> uris = new ArrayList<>();
@ -1313,11 +1315,16 @@ public class ConversationActivity extends XmppActivity
this.xmppConnectionService.getNotificationService().setIsInForeground(true);
updateConversationList();
long FirstStartTime = 0;
Bundle extras = getIntent().getExtras();
if(extras != null) {
FirstStartTime = extras.getLong("FirstStart");
}
Bundle extras = getIntent().getExtras();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (extras != null) {
FirstStartTime = extras.getLong("FirstStart");
Log.d(Config.LOGTAG, "Get first start time from StartUI: " + FirstStartTime);
}
} else {
FirstStartTime = System.currentTimeMillis();
Log.d(Config.LOGTAG, "Device is running Android < SDK 23, no restart required: " + FirstStartTime);
}
if (mPendingConferenceInvite != null) {
mPendingConferenceInvite.execute(this);

View file

@ -41,22 +41,21 @@ public class startUI extends AppCompatActivity
@AfterPermissionGranted(NeededPermissions)
private void requestNeededPermissions() {
String PREFS_NAME = "FirstStart";
SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
long FirstStartTime = FirstStart.getLong("FirstStart", 0);
if (EasyPermissions.hasPermissions(this, perms)) {
// Already have permission, start ConversationsActivity
String PREFS_NAME = "FirstStart";
SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
long FirstStartTime = FirstStart.getLong("FirstStart", 0);
Log.d(Config.LOGTAG, "All permissions granted, starting "+getString(R.string.app_name) + "(" +FirstStartTime + ")");
Intent intent = new Intent (this, ConversationActivity.class);
intent.putExtra("FirstStart", FirstStartTime);
startActivity(intent);
finish();
} else {
// set first start to 0 if there are permissions to request
String PREFS_NAME = "FirstStart";
long FirstStartTime = 0;
SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
Log.d(Config.LOGTAG, "Requesting required permissions");
SharedPreferences.Editor editor = FirstStart.edit();
editor.putLong("FirstStart", FirstStartTime);
editor.putLong("FirstStart", 0);
editor.commit();
// Do not have permissions, request them now
EasyPermissions.requestPermissions(this, getString(R.string.request_permissions_message),