List of usage examples for android.content Context checkCallingOrSelfUriPermission
@CheckResult(suggest = "#enforceCallingOrSelfUriPermission(Uri,int,String)") @PackageManager.PermissionResult public abstract int checkCallingOrSelfUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
From source file:com.anthonymandra.support.v4.provider.DocumentsContractApi19.java
public static boolean canRead(Context context, Uri self) { // Ignore if grant doesn't allow read if (context.checkCallingOrSelfUriPermission(self, Intent.FLAG_GRANT_READ_URI_PERMISSION) != PackageManager.PERMISSION_GRANTED) { return false; }//from w w w .j a va2s .c om // Ignore documents without MIME if (TextUtils.isEmpty(getRawType(context, self))) { return false; } return true; }
From source file:com.anthonymandra.support.v4.provider.DocumentsContractApi19.java
public static boolean canWrite(Context context, Uri self) { // Ignore if grant doesn't allow write if (context.checkCallingOrSelfUriPermission(self, Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != PackageManager.PERMISSION_GRANTED) { return false; }/*from w w w . j a v a2 s . c o m*/ final String type = getRawType(context, self); final int flags = queryForInt(context, self, DocumentsContract.Document.COLUMN_FLAGS, 0); // Ignore documents without MIME if (TextUtils.isEmpty(type)) { return false; } // Deletable documents considered writable if ((flags & DocumentsContract.Document.FLAG_SUPPORTS_DELETE) != 0) { return true; } if (DocumentsContract.Document.MIME_TYPE_DIR.equals(type) && (flags & DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE) != 0) { // Directories that allow create considered writable return true; } else if (!TextUtils.isEmpty(type) && (flags & DocumentsContract.Document.FLAG_SUPPORTS_WRITE) != 0) { // Writable normal files considered writable return true; } return false; }