本文整理汇总了Java中android.webkit.MimeTypeMap.getMimeTypeFromExtension方法的典型用法代码示例。如果您正苦于以下问题:Java MimeTypeMap.getMimeTypeFromExtension方法的具体用法?Java MimeTypeMap.getMimeTypeFromExtension怎么用?Java MimeTypeMap.getMimeTypeFromExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.MimeTypeMap
的用法示例。
在下文中一共展示了MimeTypeMap.getMimeTypeFromExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openFile
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
/**
* 打开文件
* @param downloadPath
*/
@ReactMethod
private void openFile(String downloadPath){
File file = new File(downloadPath);
if (!file.exists()) return;
Intent intent = new Intent(Intent.ACTION_VIEW);
String url = "file://" + file.toString();
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String mimeString = mimeTypeMap.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//设置intent的Action属性
intent.setAction(Intent.ACTION_VIEW);
//设置intent的data和Type属性。
intent.setDataAndType(Uri.parse(url), mimeString);
//跳转
mApplicationContext.startActivity(intent);
//这里最好try一下,有可能会报错。
//比如说你的MIME类型是打开邮箱,但是你手机里面没装邮箱客户端,就会报错。
}
示例2: getMimeType
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public static String getMimeType(String filePath) {
if (TextUtils.isEmpty(filePath)) {
return "";
}
String type = null;
String extension = getExtensionName(filePath.toLowerCase());
if (!TextUtils.isEmpty(extension)) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
Log.i(TAG, "url:" + filePath + " " + "type:" + type);
// FIXME
if (StringUtil.isEmpty(type) && filePath.endsWith("aac")) {
type = "audio/aac";
}
return type;
}
示例3: showNotification
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
protected void showNotification(String notificationText) {
// TODO Auto-generated method stub
NotificationCompat.Builder build = new NotificationCompat.Builder(
activity);
build.setSmallIcon(OneSheeldApplication.getNotificationIcon());
build.setContentTitle(activity.getString(R.string.data_logger_shield_name));
build.setContentText(notificationText);
build.setTicker(notificationText);
build.setWhen(System.currentTimeMillis());
build.setAutoCancel(true);
Toast.makeText(activity, notificationText, Toast.LENGTH_SHORT).show();
Vibrator v = (Vibrator) activity
.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(1000);
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String mimeFileType = mimeTypeMap.getMimeTypeFromExtension("csv");
if(Build.VERSION.SDK_INT>=24) {
Uri fileURI = FileProvider.getUriForFile(activity,
BuildConfig.APPLICATION_ID + ".provider",
new File(filePath == null || filePath.length() == 0 ? "" : filePath));
notificationIntent.setDataAndType(fileURI, mimeFileType);
}
else{
notificationIntent.setDataAndType(Uri.fromFile(new File(filePath == null
|| filePath.length() == 0 ? "" : filePath)), mimeFileType);
}
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
PendingIntent intent = PendingIntent.getActivity(activity, 0,
notificationIntent, 0);
build.setContentIntent(intent);
Notification notification = build.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) activity
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int) new Date().getTime(), notification);
}
示例4: getMimeType
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
static String getMimeType(File file) {
if (file.isDirectory()) {
return null;
}
String type = "*/*";
final String extension = getExtension(file.getName());
if (extension != null && !extension.isEmpty()) {
final String extensionLowerCase = extension.toLowerCase(Locale
.getDefault());
final MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extensionLowerCase);
if (type == null) {
type = MIME_TYPES.get(extensionLowerCase);
}
}
if (type == null) type = "*/*";
return type;
}
示例5: getMimeByExt
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public final static String getMimeByExt(String ext, String defValue)
{
if (str(ext))
{
String[] descr = getTypeDescrByExt(ext);
if (descr != null)
return descr[1];
// ask the system
MimeTypeMap mime_map = MimeTypeMap.getSingleton();
if (mime_map != null)
{
String mime = mime_map.getMimeTypeFromExtension(ext.substring(1));
if (str(mime))
return mime;
}
}
return defValue;
}
示例6: openFileInSystem
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public static void openFileInSystem(String path, Context context) {
try {
MimeTypeMap myMime = MimeTypeMap.getSingleton();
Intent newIntent = new Intent(Intent.ACTION_VIEW);
String mimeType = myMime.getMimeTypeFromExtension(fileExt(path).substring(1));
newIntent.setDataAndType(Uri.fromFile(new File(path)), mimeType);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(newIntent);
} catch (Exception e) {
Toast.makeText(context, "No handler for this type of file.", Toast.LENGTH_LONG).show();
}
}
示例7: downloadApk
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public void downloadApk(String requestUrl, String dir, String filename)
{
Uri resource = Uri.parse(requestUrl);
DownloadManager.Request request = new DownloadManager.Request(resource);
request.setAllowedNetworkTypes(Request.NETWORK_MOBILE | Request.NETWORK_WIFI);
request.setAllowedOverRoaming(false);
//设置文件类型
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String mimeString = mimeTypeMap.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(requestUrl));
request.setMimeType(mimeString);
//在通知栏中显示
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD)
{
request.setShowRunningNotification(true);
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
// 显示下载界面
request.setVisibleInDownloadsUi(true);
//sdcard的目录下的download文件夹 /**AppConfig.DIR_APK*/
request.setDestinationInExternalPublicDir("/download/", filename + ".apk");
request.setTitle(filename + "");
long id = mDownloadManager.enqueue(request);
mTask.put(id, filename + "");
}
示例8: getMimeType
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
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;
}
示例9: getMimeTypeForFile
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
private static String getMimeTypeForFile(String uri) {
String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(uri);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
}
示例10: getMimeType
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
static public String getMimeType(File file) {
String mimeType;
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
final String fullName = file.getName();
int dotPos = fullName.lastIndexOf('.');
if (dotPos >= 0 && dotPos < fullName.length()) {
mimeType = mimeTypeMap.getMimeTypeFromExtension(fullName.substring(dotPos + 1));
if (mimeType == null) {
mimeType = "";
}
} else {
mimeType = "";
}
return mimeType;
}
示例11: fileIsMimeType
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public static boolean fileIsMimeType(File file, String mimeType, MimeTypeMap mimeTypeMap) {
if (mimeType == null || mimeType.equals("*/*")) {
return true;
} else {
// get the file mime type
String filename = file.toURI().toString();
int dotPos = filename.lastIndexOf('.');
if (dotPos == -1) {
return false;
}
String fileExtension = filename.substring(dotPos + 1).toLowerCase();
String fileType = mimeTypeMap.getMimeTypeFromExtension(fileExtension);
if (fileType == null) {
return false;
}
// check the 'type/subtype' pattern
if (fileType.equals(mimeType)) {
return true;
}
// check the 'type/*' pattern
int mimeTypeDelimiter = mimeType.lastIndexOf('/');
if (mimeTypeDelimiter == -1) {
return false;
}
String mimeTypeMainType = mimeType.substring(0, mimeTypeDelimiter);
String mimeTypeSubtype = mimeType.substring(mimeTypeDelimiter + 1);
if (!mimeTypeSubtype.equals("*")) {
return false;
}
int fileTypeDelimiter = fileType.lastIndexOf('/');
if (fileTypeDelimiter == -1) {
return false;
}
String fileTypeMainType = fileType.substring(0, fileTypeDelimiter);
if (fileTypeMainType.equals(mimeTypeMainType)) {
return true;
}
}
return false;
}
示例12: getMimeType
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
/**
* 获取文件的MIME类型
*
* @param pathOrUrl the path or url
* @return mime type
*/
public static String getMimeType(String pathOrUrl) {
String ext = getExtension(pathOrUrl);
MimeTypeMap map = MimeTypeMap.getSingleton();
String mimeType;
if (map.hasExtension(ext)) {
mimeType = map.getMimeTypeFromExtension(ext);
} else {
mimeType = "*/*";
}
LogUtils.debug(pathOrUrl + ": " + mimeType);
return mimeType;
}
示例13: shareFile
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
static void shareFile(Activity activity, String url) {
try {
File myFile = new File(url);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = myFile.getName().substring(myFile.getName().lastIndexOf(".") + 1);
String type = mime.getMimeTypeFromExtension(ext);
Intent sharingIntent = new Intent("android.intent.action.SEND");
sharingIntent.setType(type);
sharingIntent.putExtra("android.intent.extra.STREAM", Uri.fromFile(myFile));
activity.startActivity(Intent.createChooser(sharingIntent, activity.getString(R.string.shareWith)));
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: openFileByAnotherApp
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
private boolean openFileByAnotherApp(File file) {
//don't open compiled file
if (FileUtils.hasExtension(file, "class", "dex", "jar")) {
Toast.makeText(this, "Unable to open file", Toast.LENGTH_SHORT).show();
return false;
}
try {
Uri uri;
if (Build.VERSION.SDK_INT >= 24) {
uri = FileProvider.getUriForFile(this, getPackageName() + ".provider", file);
} else {
uri = Uri.fromFile(file);
}
//create intent open file
MimeTypeMap myMime = MimeTypeMap.getSingleton();
Intent intent = new Intent(Intent.ACTION_VIEW);
String ext = FileUtils.fileExt(file.getPath());
String mimeType = myMime.getMimeTypeFromExtension(ext != null ? ext : "");
intent.setDataAndType(uri, mimeType);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
return true;
}
示例15: shareFile
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public static void shareFile(Context context, String url) {
try {
File myFile = new File(url);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = myFile.getName().substring(myFile.getName().lastIndexOf(".") + 1);
String type = mime.getMimeTypeFromExtension(ext);
Intent sharingIntent = new Intent("android.intent.action.SEND");
sharingIntent.setType(type);
sharingIntent.putExtra("android.intent.extra.STREAM", Uri.fromFile(myFile));
context.startActivity(Intent.createChooser(sharingIntent, "Share using"));
} catch (Exception e) {
e.printStackTrace();
}
}