Skip to content

Commit

Permalink
ankidroid#5740 - Add Dialog Requesting Permissions
Browse files Browse the repository at this point in the history
Some users din't feel comfortable about us requiring access to
external storage.

We explain that we don't perform any malicious activities with this
in order to hopefully alleviate concerns.
  • Loading branch information
david-allison committed Mar 21, 2020
1 parent 75d59fd commit 3c8902e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.provider.Settings;

import com.afollestad.materialdialogs.GravityEnum;
import com.google.android.material.snackbar.Snackbar;

import androidx.annotation.Nullable;
Expand All @@ -55,6 +57,7 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -365,6 +368,7 @@ protected void onCreate(Bundle savedInstanceState) throws SQLException {
Timber.d("onCreate()");
SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
// Open Collection on UI thread while splash screen is showing
// DEFECT: If this returns false, we have a dialog/permissions check, but still perform UI work.
boolean colOpen = firstCollectionOpen();

// Then set theme and content view
Expand Down Expand Up @@ -456,8 +460,17 @@ private boolean firstCollectionOpen() {
return CollectionHelper.getInstance().getColSafe(this) != null;
} else {
// Request storage permission if we don't have it (e.g. on Android 6.0+)
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_STORAGE_PERMISSION);
// Request storage permission if we don't have it (e.g. on Android 6.0+)
new MaterialDialog.Builder(this)
.title(R.string.collection_load_welcome_request_permissions_title)
.titleGravity(GravityEnum.CENTER)
.content(R.string.collection_load_welcome_request_permissions_details)
.positiveText(R.string.dialog_ok)
.onPositive((innerDialog, innerWhich) -> ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_STORAGE_PERMISSION))
.cancelable(false)
.canceledOnTouchOutside(false)
.show();
return false;
}
}
Expand Down
4 changes: 4 additions & 0 deletions AnkiDroid/src/main/res/values/03-dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,8 @@
<string name="empty_cards_none">No empty cards</string>
<string name="empty_cards_count">Cards to delete: %d</string>
<string name="empty_cards_deleted">Cards deleted: %d</string>

<!-- Initial collection load -->
<string name="collection_load_welcome_request_permissions_title">Welcome to AnkiDroid!</string>
<string name="collection_load_welcome_request_permissions_details">We require storage access to store your AnkiDroid collection, including media and backups. We do not access any of your media or files. Our code is open-source, written by volunteers, and trusted by millions.\n\nIf you have any questions, please access our in-app manual or visit our support forums.\n\nThank you for trying AnkiDroid!\n—AnkiDroid Development Team</string>
</resources>

0 comments on commit 3c8902e

Please sign in to comment.