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 android-classyshark by google.
the class MainActivity method onStart.
@Override
public void onStart() {
super.onStart();
final ArrayList<AppListNode> apps = new ArrayList<>();
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
for (Object object : pkgAppsList) {
ResolveInfo info = (ResolveInfo) object;
File file = new File(info.activityInfo.applicationInfo.publicSourceDir);
AppListNode aln = new AppListNode();
aln.name = info.activityInfo.applicationInfo.processName.toString();
aln.file = file;
apps.add(aln);
}
Collections.sort(apps);
final StableArrayAdapter adapter = new StableArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, convert(apps));
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
MimeTypeMap myMime = MimeTypeMap.getSingleton();
Intent newIntent = new Intent(MainActivity.this, ClassesListActivity.class);
String mimeType = myMime.getMimeTypeFromExtension("apk");
newIntent.setDataAndType(Uri.fromFile(apps.get(position).file), mimeType);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newIntent.putExtra(APP_NAME, apps.get(position).name);
try {
startActivity(newIntent);
} catch (ActivityNotFoundException e) {
}
}
});
}
use of android.webkit.MimeTypeMap in project qksms by moezbhatti.
the class VideoModel method initFromFile.
private void initFromFile(Uri uri) {
String path = uri.getPath();
mSrc = path.substring(path.lastIndexOf('/') + 1);
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String extension = MimeTypeMap.getFileExtensionFromUrl(mSrc);
if (TextUtils.isEmpty(extension)) {
// getMimeTypeFromExtension() doesn't handle spaces in filenames nor can it handle
// urlEncoded strings. Let's try one last time at finding the extension.
int dotPos = mSrc.lastIndexOf('.');
if (0 <= dotPos) {
extension = mSrc.substring(dotPos + 1);
}
}
mContentType = mimeTypeMap.getMimeTypeFromExtension(extension);
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "New VideoModel initFromFile created:" + " mSrc=" + mSrc + " mContentType=" + mContentType + " mUri=" + uri);
}
}
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;
}
Aggregations