use of android.webkit.MimeTypeMap in project AndLang by wugemu.
the class HttpU method downVideo.
public void downVideo(Context mContext, String url) {
// 获取okHttp对象get请求
try {
String filename = url.substring(url.lastIndexOf("/") + 1);
// 创建下载任务
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
// 漫游网络是否可以下载
request.setAllowedOverRoaming(true);
// 设置文件类型,可以在下载结束后自动打开该文件
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String mimeString = mimeTypeMap.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url));
request.setMimeType(mimeString);
// 在通知栏中显示,默认就是显示的
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setVisibleInDownloadsUi(true);
// sdcard的目录下的download文件夹,必须设置
request.setDestinationInExternalPublicDir("/" + BaseLangApplication.tmpImageDir + "/", filename);
// 将下载请求加入下载队列
DownloadManager downloadManager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
// 加入下载队列后会给该任务返回一个long型的id,
// 通过该id可以取消任务,重启任务等等,看上面源码中框起来的方法
downloadManager.enqueue(request);
} catch (Exception e) {
e.printStackTrace();
}
}
use of android.webkit.MimeTypeMap in project dropbox-sdk-java by dropbox.
the class FilesActivity method viewFileInExternalApp.
private void viewFileInExternalApp(File result) {
Intent intent = new Intent(Intent.ACTION_VIEW);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = result.getName().substring(result.getName().indexOf(".") + 1);
String type = mime.getMimeTypeFromExtension(ext);
intent.setDataAndType(Uri.fromFile(result), type);
// Check for a handler first to avoid a crash
PackageManager manager = getPackageManager();
List<ResolveInfo> resolveInfo = manager.queryIntentActivities(intent, 0);
if (resolveInfo.size() > 0) {
startActivity(intent);
}
}
use of android.webkit.MimeTypeMap in project FileDownloaderManager by arlyxiao.
the class DownloadLib method get_mime_type.
// protected void open_file() {
// String full_file_path = Environment.getExternalStorageDirectory().getAbsolutePath()
// + save_file_path;
// Log.i("要打开的文件 ", full_file_path);
// File file = new File(full_file_path);
//
// try {
// Intent intent = new Intent(Intent.ACTION_VIEW);
// // intent.setAction(Intent.ACTION_VIEW);
// intent.setDataAndType(Uri.fromFile(file), get_mime_type(file.getAbsolutePath()));
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(intent);
// } catch (Exception e) {
// Log.i("文件打开错误 ", e.getMessage());
// }
// }
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 TeamCityApp by vase4kin.
the class ArtifactRouterImpl method startFileActivity.
/**
* {@inheritDoc}
*/
@Override
public void startFileActivity(File file) {
MimeTypeMap map = MimeTypeMap.getSingleton();
String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName());
String type = map.getMimeTypeFromExtension(ext);
if (type == null) {
type = ALL_FILES_TYPE;
}
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = FileProvider.getUriForFile(mActivity, BuildConfig.APPLICATION_ID + ".provider", file);
intent.setDataAndType(data, type);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
// User couldn't have app with type intent
try {
mActivity.startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
intent.setDataAndType(data, ALL_FILES_TYPE);
mActivity.startActivity(intent);
}
}
use of android.webkit.MimeTypeMap in project iNaturalistAndroid by inaturalist.
the class ObservationEditor method getExtension.
public static String getExtension(Context context, Uri uri) {
String extension;
// Check uri format to avoid null
if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
// If scheme is a content
final MimeTypeMap mime = MimeTypeMap.getSingleton();
extension = mime.getExtensionFromMimeType(context.getContentResolver().getType(uri));
} else {
// If scheme is a File
// This will replace white spaces with %20 and also other special characters. This will avoid returning null values on file name with spaces and special characters.
extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
}
return extension;
}
Aggregations