use of android.webkit.MimeTypeMap in project smartmodule by carozhu.
the class DownloadService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (!blnPermission) {
return super.onStartCommand(intent, flags, startId);
}
if (intent != null) {
Bundle bundle = intent.getExtras();
String downloadUrl = bundle.getString("downloadUrl");
fileName = bundle.getString("fileName");
appDowunPath = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
//Log.i("dirType","onStartCommand appDowunPath == "+appDowunPath + " fileName == "+fileName);
File downloadFile = new File(appDowunPath + "/" + fileName);
if (downloadFile.exists()) {
installAPK(downloadFile);
return super.onStartCommand(intent, flags, startId);
}
//创建下载任务,downloadUrl就是下载链接
request = new DownloadManager.Request(Uri.parse(downloadUrl));
//设置下载网络现在方式
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
//漫游网络是否可以下载
request.setAllowedOverRoaming(true);
/*
* 设置允许使用的网络类型, 可选值:
* NETWORK_MOBILE: 移动网络
* NETWORK_WIFI: WIFI网络
* NETWORK_BLUETOOTH: 蓝牙网络
* 默认为所有网络都允许
*/
// request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
//设置带通知栏下载
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setVisibleInDownloadsUi(true);
//更多路径下载设置参考:http://www.cnblogs.com/zhaoyanjun/p/4591960.html
//设置路径有多种方式 指定下载路径和下载文件名(设置下载文件的保存位置)
// 1 TYPE
//request.setDestinationInExternalFilesDir(this, null, mApkDir);//自己制定下载路径
// 2 TYPE
//File saveFile = new File(Environment.getExternalStorageDirectory(),fileName+".apk");
// 3 TYPE
//request.setDestinationUri(Uri.fromFile(saveFile));
// 4 TYPE
//request.setDestinationInExternalPublicDir(dirType, fileName);
// 5 TYpe 设置到app下载目录
String appDownloadPath = Environment.DIRECTORY_DOWNLOADS;
//目录: Android -> data -> com.app -> files -> Download
request.setDestinationInExternalFilesDir(this, appDownloadPath, fileName);
/*在默认的情况下,通过Download Manager下载的文件是不能被Media Scanner扫描到的 。
进而这些下载的文件(音乐、视频等)就不会在Gallery 和 Music Player这样的应用中看到。
为了让下载的音乐文件可以被其他应用扫描到,我们需要调用Request对象的
*/
request.allowScanningByMediaScanner();
//设置请求的Mime http://www.jianshu.com/p/7ad92b3d9069
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
request.setMimeType(mimeTypeMap.getMimeTypeFromExtension(downloadUrl));
//将下载任务加入下载队列,否则不会进行下载
mTaskId = mDownloadManager.enqueue(request);
/*
参考来自:http://www.cnblogs.com/zhaoyanjun/p/4591960.html
下载管理器中有很多下载项,怎么知道一个资源已经下载过,避免重复下载呢?
我的项目中的需求就是apk更新下载,用户点击更新确定按钮,第一次是直接下载,
后面如果用户连续点击更新确定按钮,就不要重复下载了。
可以看出来查询和操作数据库查询一样的
*/
/*验证没查询到,待解决
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(mTaskId);
Cursor cursor = mDownloadManager.query(query);
if (!cursor.moveToFirst()) {// 没有记录
} else {
}
*/
//注册广播接收者,监听下载状态,通知栏点击状态
registerReceiver(new DownloadManagerReceiver(), new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
//return super.onStartCommand(intent, flags, startId);
return Service.START_STICKY;
}
use of android.webkit.MimeTypeMap in project instructure-android by instructure.
the class FileUploadUtils method getMimeTypeFromFileNameWithExtension.
public static String getMimeTypeFromFileNameWithExtension(String fileNameWithExtension) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
int index = fileNameWithExtension.indexOf(".");
String ext = "";
if (index != -1) {
// Add one so the dot isn't included
ext = fileNameWithExtension.substring(index + 1).toLowerCase();
}
return mime.getMimeTypeFromExtension(ext);
}
use of android.webkit.MimeTypeMap in project instructure-android by instructure.
the class FileUtilities method getMimeType.
public static String getMimeType(String url) {
String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
}
use of android.webkit.MimeTypeMap in project instructure-android by instructure.
the class FileUtils method getMimeType.
public static String getMimeType(String url) {
String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
}
use of android.webkit.MimeTypeMap in project instructure-android by instructure.
the class FileUploadUtils method getMimeTypeFromFileNameWithExtension.
public static String getMimeTypeFromFileNameWithExtension(String fileNameWithExtension) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
int index = fileNameWithExtension.indexOf(".");
String ext = "";
if (index != -1) {
// Add one so the dot isn't included
ext = fileNameWithExtension.substring(index + 1).toLowerCase();
}
return mime.getMimeTypeFromExtension(ext);
}
Aggregations