Skip to content

Android M permissions #21

Description

@enricocid

Why don't You ask for permissions on main activity? If one goes to the settings would not be able to change the 'Wallpaper export location' since permissions are asked only when downloading a wallpaper. I think it would be easier and it would require only few lines of code

private final static int READ_EXTERNAL_STORAGE_PERMISSION_REQUEST=1;

and onCreate

if (Build.VERSION.SDK_INT >= 23 && PermissionChecker.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PermissionChecker.PERMISSION_GRANTED) {
            requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, READ_EXTERNAL_STORAGE_PERMISSION_REQUEST);
        }

You can also explain why you need permissions if You want

@Override
    public void onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults) {
        if(requestCode==READ_EXTERNAL_STORAGE_PERMISSION_REQUEST && grantResults[0]!=PermissionChecker.PERMISSION_GRANTED) {
            Utils.showMessageDialog();
        }
    }

showing a simple dialog using material dialogs library:)

public void showMessageDialog() {
        new MaterialDialog.Builder(this)
                .title(R.string.permissions_title)
                .content(R.string.explain_why)
                .positiveText(android.R.string.ok)
                .negativeText(android.R.string.no)
                .show();
    }

just a hint :)
I don't have a working as, or I would have sent a pull request:)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions