PDDStudio / earthview-android

A library to include 'EarthView with Google' into your application with ease.
139 stars 28 forks source link

Android M permissions #21

Open enricocid opened 8 years ago

enricocid commented 8 years ago

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:)

PDDStudio commented 8 years ago

Thanks for pointing out, indeed you can only change the export location after granting storage permission (which appears when downloading a wallpaper. I'm going to have a look at this.