use of android.webkit.MimeTypeMap in project robolectric by robolectric.
the class ShadowMimeTypeMapTest method getSingletonShouldAlwaysReturnSameInstance.
@Test
public void getSingletonShouldAlwaysReturnSameInstance() {
MimeTypeMap firstInstance = MimeTypeMap.getSingleton();
MimeTypeMap secondInstance = MimeTypeMap.getSingleton();
assertSame(firstInstance, secondInstance);
}
use of android.webkit.MimeTypeMap in project ETSMobile-Android2 by ApplETS.
the class MoodleCourseDetailsFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle onSavedInstanceState) {
super.onActivityCreated(onSavedInstanceState);
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(enqueue);
Cursor c = dm.query(query);
if (c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
MimeTypeMap map = MimeTypeMap.getSingleton();
String ext = MimeTypeMap.getFileExtensionFromUrl(uriString);
String type = map.getMimeTypeFromExtension(ext);
Uri uri = Uri.parse(uriString);
if (type == null)
type = "*/*";
Intent openFile = new Intent(Intent.ACTION_VIEW);
openFile.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
File file = new File(uri.getPath());
Uri fileProviderUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", file);
openFile.setDataAndType(fileProviderUri, type);
} else {
openFile.setDataAndType(uri, type);
}
try {
startActivity(openFile);
} catch (ActivityNotFoundException e) {
Toast.makeText(getActivity(), getString(R.string.cannot_open_file), Toast.LENGTH_SHORT).show();
}
}
}
}
}
};
getActivity().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
queryMoodleCoreCourses(moodleCourseId);
}
use of android.webkit.MimeTypeMap in project ETSMobile-Android2 by ApplETS.
the class MoodleCourseDetailsFragment method downloadMoodleObject.
/**
* Downloads an given Moodle item into the user's device.
* @param item the item to be downloaded.
*/
@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
void downloadMoodleObject(MoodleModuleContent item) {
String url = item.getFileurl() + "&token=" + ApplicationManager.userCredentials.getMoodleToken();
Uri uri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, item.getFilename());
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
MimeTypeMap mimetype = MimeTypeMap.getSingleton();
String extension = FilenameUtils.getExtension(item.getFilename());
request.setMimeType(mimetype.getMimeTypeFromExtension(extension));
dm = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
enqueue = dm.enqueue(request);
}
use of android.webkit.MimeTypeMap in project FileDownloaderManager by arlyxiao.
the class DownloadDoneNotification method get_mime_type.
private String get_mime_type(String url) {
String[] parts = url.split("\\.");
String extension = parts[parts.length - 1];
String type = null;
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
}
use of android.webkit.MimeTypeMap in project mobile-android by photo.
the class NewPhotoObserver method getMimeType.
/**
* Get the mime type for the file
*
* @param file
* @return
*/
public static String getMimeType(File file) {
String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).getPath());
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension.toLowerCase());
}
CommonUtils.debug(TAG, "File: %1$s; extension %2$s; MimeType: %3$s", file.getAbsolutePath(), extension, type);
return type;
}
Aggregations