Methods Summary |
---|
public static boolean | canRead(android.content.Context context, android.net.Uri self)
// Ignore if grant doesn't allow read
if (context.checkCallingOrSelfUriPermission(self, Intent.FLAG_GRANT_READ_URI_PERMISSION)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
// Ignore documents without MIME
if (TextUtils.isEmpty(getRawType(context, self))) {
return false;
}
return true;
|
public static boolean | canWrite(android.content.Context context, android.net.Uri self)
// Ignore if grant doesn't allow write
if (context.checkCallingOrSelfUriPermission(self, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
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;
|
private static void | closeQuietly(java.lang.AutoCloseable closeable)
if (closeable != null) {
try {
closeable.close();
} catch (RuntimeException rethrown) {
throw rethrown;
} catch (Exception ignored) {
}
}
|
public static boolean | delete(android.content.Context context, android.net.Uri self)
return DocumentsContract.deleteDocument(context.getContentResolver(), self);
|
public static boolean | exists(android.content.Context context, android.net.Uri self)
final ContentResolver resolver = context.getContentResolver();
Cursor c = null;
try {
c = resolver.query(self, new String[] {
DocumentsContract.Document.COLUMN_DOCUMENT_ID }, null, null, null);
return c.getCount() > 0;
} catch (Exception e) {
Log.w(TAG, "Failed query: " + e);
return false;
} finally {
closeQuietly(c);
}
|
public static java.lang.String | getName(android.content.Context context, android.net.Uri self)
return queryForString(context, self, DocumentsContract.Document.COLUMN_DISPLAY_NAME, null);
|
private static java.lang.String | getRawType(android.content.Context context, android.net.Uri self)
return queryForString(context, self, DocumentsContract.Document.COLUMN_MIME_TYPE, null);
|
public static java.lang.String | getType(android.content.Context context, android.net.Uri self)
final String rawType = getRawType(context, self);
if (DocumentsContract.Document.MIME_TYPE_DIR.equals(rawType)) {
return null;
} else {
return rawType;
}
|
public static boolean | isDirectory(android.content.Context context, android.net.Uri self)
return DocumentsContract.Document.MIME_TYPE_DIR.equals(getRawType(context, self));
|
public static boolean | isDocumentUri(android.content.Context context, android.net.Uri self)
return DocumentsContract.isDocumentUri(context, self);
|
public static boolean | isFile(android.content.Context context, android.net.Uri self)
final String type = getRawType(context, self);
if (DocumentsContract.Document.MIME_TYPE_DIR.equals(type) || TextUtils.isEmpty(type)) {
return false;
} else {
return true;
}
|
public static long | lastModified(android.content.Context context, android.net.Uri self)
return queryForLong(context, self, DocumentsContract.Document.COLUMN_LAST_MODIFIED, 0);
|
public static long | length(android.content.Context context, android.net.Uri self)
return queryForLong(context, self, DocumentsContract.Document.COLUMN_SIZE, 0);
|
private static int | queryForInt(android.content.Context context, android.net.Uri self, java.lang.String column, int defaultValue)
return (int) queryForLong(context, self, column, defaultValue);
|
private static long | queryForLong(android.content.Context context, android.net.Uri self, java.lang.String column, long defaultValue)
final ContentResolver resolver = context.getContentResolver();
Cursor c = null;
try {
c = resolver.query(self, new String[] { column }, null, null, null);
if (c.moveToFirst() && !c.isNull(0)) {
return c.getLong(0);
} else {
return defaultValue;
}
} catch (Exception e) {
Log.w(TAG, "Failed query: " + e);
return defaultValue;
} finally {
closeQuietly(c);
}
|
private static java.lang.String | queryForString(android.content.Context context, android.net.Uri self, java.lang.String column, java.lang.String defaultValue)
final ContentResolver resolver = context.getContentResolver();
Cursor c = null;
try {
c = resolver.query(self, new String[] { column }, null, null, null);
if (c.moveToFirst() && !c.isNull(0)) {
return c.getString(0);
} else {
return defaultValue;
}
} catch (Exception e) {
Log.w(TAG, "Failed query: " + e);
return defaultValue;
} finally {
closeQuietly(c);
}
|