Skip to content
This repository has been archived by the owner on Feb 27, 2021. It is now read-only.

Commit

Permalink
Adds grant permissions request for marshmallow and later. Since not g…
Browse files Browse the repository at this point in the history
…ranted permissions are unhandled and cause runtime exceptions, the grant permission request will pop up every time when entering accounts activity until all permissions are granted.
  • Loading branch information
G00fY2 committed May 15, 2017
1 parent e3b17b6 commit f738a30
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ ckchangelog=1.2.2
glide=3.8.0
tokenautocomplete=2.0.8
safecontentresolver=0.9.0
showcaseview=5.4.3
showcaseview=5.4.3
dexter=4.1.0
1 change: 1 addition & 0 deletions k9mail/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
compile "com.splitwise:tokenautocomplete:${tokenautocomplete}"
compile "de.cketti.safecontentresolver:safe-content-resolver-v14:${safecontentresolver}"
compile "com.github.amlcurran.showcaseview:library:${showcaseview}"
compile "com.karumi:dexter:${dexter}"

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'

Expand Down
18 changes: 18 additions & 0 deletions k9mail/src/main/java/com/fsck/k9/activity/Accounts.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package com.fsck.k9.activity;

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
Expand All @@ -15,6 +16,8 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBar;
Expand Down Expand Up @@ -81,6 +84,8 @@
import com.fsck.k9.search.SearchSpecification.Attribute;
import com.fsck.k9.search.SearchSpecification.SearchField;
import com.fsck.k9.view.ColorChip;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.listener.multi.DialogOnAnyDeniedMultiplePermissionsListener;

import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -432,6 +437,19 @@ public void onCreate(Bundle icicle) {
mNonConfigurationInstance.restore(this);
}

if (Build.VERSION.SDK_INT >= VERSION_CODES.M) {
Dexter.withActivity(Accounts.this)
.withPermissions(
Manifest.permission.READ_CONTACTS,
Manifest.permission.WRITE_EXTERNAL_STORAGE
).withListener(DialogOnAnyDeniedMultiplePermissionsListener.Builder
.withContext(Accounts.this)
.withTitle("Contacts & storage permission")
.withMessage("Both contact and storage permission are needed for K-9 to work properly.")
.withButtonText(android.R.string.ok)
.build()).check();
}

ChangeLog cl = new ChangeLog(this);
if (cl.isFirstRun()) {
cl.getLogDialog().show();
Expand Down

0 comments on commit f738a30

Please sign in to comment.