当前位置: 首页>>代码示例>>Java>>正文


Java MimeTypeMap.getMimeTypeFromExtension方法代码示例

本文整理汇总了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类型是打开邮箱,但是你手机里面没装邮箱客户端,就会报错。
}
 
开发者ID:liuhong1happy,项目名称:react-native-download-manager,代码行数:23,代码来源:DownloadFileManager.java

示例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;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:20,代码来源:FileUtil.java

示例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);
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:39,代码来源:DataLoggerShield.java

示例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;
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:21,代码来源:MimeTypes.java

示例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;
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:19,代码来源:FileUtils.java

示例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();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:DataUtil.java

示例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 + "");
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:34,代码来源:DownloadFactory.java

示例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;
}
 
开发者ID:PlutoArchitecture,项目名称:Pluto-Android,代码行数:10,代码来源:BitmapUtil.java

示例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;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:10,代码来源:LocalHTTPD.java

示例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;
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:16,代码来源:InfoDialog.java

示例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;
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:41,代码来源:FileUtil.java

示例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;
}
 
开发者ID:mainh,项目名称:MainCalendar,代码行数:19,代码来源:FileUtils.java

示例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();
    }
}
 
开发者ID:enricocid,项目名称:Gallery-example,代码行数:15,代码来源:ShareUtils.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:28,代码来源:ProjectManagerActivity.java

示例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();
    }
}
 
开发者ID:hoanganhtuan95ptit,项目名称:EditPhoto,代码行数:15,代码来源:Utils.java


注:本文中的android.webkit.MimeTypeMap.getMimeTypeFromExtension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。