static void getObjectDocumentValues(
ContentValues values, int deviceId, String parentId, MtpObjectInfo info) {
values.clear();
- final String mimeType = info.getFormat() == MtpConstants.FORMAT_ASSOCIATION ?
- DocumentsContract.Document.MIME_TYPE_DIR :
- MediaFile.getMimeTypeForFormatCode(info.getFormat());
+ final String mimeType = getMimeType(info);
int flag = 0;
if (info.getProtectionStatus() == 0) {
flag |= Document.FLAG_SUPPORTS_DELETE |
values.put(Document.COLUMN_SIZE, info.getCompressedSize());
}
+ private static String getMimeType(MtpObjectInfo info) {
+ if (info.getFormat() == MtpConstants.FORMAT_ASSOCIATION) {
+ return DocumentsContract.Document.MIME_TYPE_DIR;
+ }
+ final String formatCodeMimeType = MediaFile.getMimeTypeForFormatCode(info.getFormat());
+ if (formatCodeMimeType != null) {
+ return formatCodeMimeType;
+ }
+ return MediaFile.getMimeTypeForFile(info.getName());
+ }
+
static String[] strings(Object... args) {
final String[] results = new String[args.length];
for (int i = 0; i < args.length; i++) {
public ParcelFileDescriptor openDocument(
String documentId, String mode, CancellationSignal signal)
throws FileNotFoundException {
+ if (DEBUG) {
+ Log.d(TAG, "openDocument: " + documentId);
+ }
final Identifier identifier = mDatabase.createIdentifier(documentId);
try {
openDevice(identifier.mDeviceId);
@Override
public String createDocument(String parentDocumentId, String mimeType, String displayName)
throws FileNotFoundException {
+ if (DEBUG) {
+ Log.d(TAG, "createDocument: " + displayName);
+ }
try {
final Identifier parentId = mDatabase.createIdentifier(parentDocumentId);
openDevice(parentId.mDeviceId);