Example usage for android.content UriPermission isReadPermission

List of usage examples for android.content UriPermission isReadPermission

Introduction

In this page you can find the example usage for android.content UriPermission isReadPermission.

Prototype

public boolean isReadPermission() 

Source Link

Document

Returns if this permission offers read access.

Usage

From source file:com.xperia64.timidityae.TimidityActivity.java

@SuppressLint("NewApi")
public void initCallback() {
    if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        List<UriPermission> permissions = getContentResolver().getPersistedUriPermissions();
        int trueExt = 0;
        for (File f : getExternalFilesDirs(null)) {
            if (f != null)
                trueExt++;/*from  ww  w  . j  ava 2  s  . c  o m*/
        }
        if ((permissions == null || permissions.isEmpty()) && Globals.shouldLolNag && trueExt > 1) {
            new AlertDialog.Builder(this).setTitle("SD Card Access").setCancelable(false).setMessage(
                    "Would you like to give Timidity AE write access to your external sd card? This is recommended if you're converting files or would like to place Timidity AE's data directory there. Problems may occur if a directory other than the root of your SD card is selected.")
                    .setPositiveButton("Yes", new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
                            startActivityForResult(intent, 42);
                        }

                    }).setNegativeButton("No, do not ask again", new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Globals.prefs.edit().putBoolean("shouldLolNag", Globals.shouldLolNag = false)
                                    .commit();
                            initCallback2();
                        }

                    }).setNeutralButton("No", new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            initCallback2();
                        }
                    }).show();
        } else {
            for (UriPermission permission : permissions) {
                if (permission.isReadPermission() && permission.isWritePermission()) {
                    Globals.theFold = permission.getUri();
                }
            }

            initCallback2();
        }
    } else {
        initCallback2();
    }
}