當前位置: 首頁>>代碼示例>>Java>>正文


Java MimeTypeMap.getSingleton方法代碼示例

本文整理匯總了Java中android.webkit.MimeTypeMap.getSingleton方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeTypeMap.getSingleton方法的具體用法?Java MimeTypeMap.getSingleton怎麽用?Java MimeTypeMap.getSingleton使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.webkit.MimeTypeMap的用法示例。


在下文中一共展示了MimeTypeMap.getSingleton方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例3: getMimeType

import android.webkit.MimeTypeMap; //導入方法依賴的package包/類
private static String getMimeType(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;
}
 
開發者ID:azmedien,項目名稱:kolibri-android,代碼行數:19,代碼來源:CardboardActivity.java

示例4: 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

示例5: openApk

import android.webkit.MimeTypeMap; //導入方法依賴的package包/類
private static boolean openApk(Context context, File file) {
    try {
        Uri uri;
        if (Build.VERSION.SDK_INT >= 24) {
            uri = FileProvider.getUriForFile(context, context.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);
        context.startActivity(intent);
    } catch (Exception e) {
        Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
    }
    return true;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:23,代碼來源:RootUtils.java

示例6: 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

示例7: 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

示例8: 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

示例9: listFiles

import android.webkit.MimeTypeMap; //導入方法依賴的package包/類
File[] listFiles(@Nullable String mimeType, @Nullable String[] extensions) {
    File[] contents = parentFolder.listFiles();
    List<File> results = new ArrayList<>();
    if (contents != null) {
        MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
        for (File fi : contents) {
            if (fi.isDirectory()) {
                results.add(fi);
            } else {
                if (extensions != null) {
                    boolean found = false;
                    for (String ext : extensions) {
                        if (fi.getName().toLowerCase().endsWith(ext.toLowerCase())) {
                            found = true;
                            break;
                        }
                    }
                    if (found) results.add(fi);
                } else if (mimeType != null) {
                    if (fileIsMimeType(fi, mimeType, mimeTypeMap)) {
                        results.add(fi);
                    }
                }
            }
        }
        Collections.sort(results, new FileSorter());
        return results.toArray(new File[results.size()]);
    }
    return null;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:FileChooserDialog.java

示例10: 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

示例11: getCategoryByExt

import android.webkit.MimeTypeMap; //導入方法依賴的package包/類
public final static String getCategoryByExt(String ext)
{
    if (str(ext))
    {
        String[] descr = getTypeDescrByExt(ext);
        if (descr != null)
            return descr[2];
        // ask the system
        MimeTypeMap mime_map = MimeTypeMap.getSingleton();
        if (mime_map != null)
        {
            String mime = mime_map.getMimeTypeFromExtension(ext.substring(1));
            if (str(mime))
            {
                String type = mime.substring(0, mime.indexOf('/'));
                if (type.compareTo("text") == 0)
                    return C_TEXT;
                if (type.compareTo("image") == 0)
                    return C_IMAGE;
                if (type.compareTo("audio") == 0)
                    return C_AUDIO;
                if (type.compareTo("video") == 0)
                    return C_VIDEO;
                if (type.compareTo("application") == 0)
                    return C_APP;
            }
        }
    }
    return C_UNKNOWN;
}
 
開發者ID:mkulesh,項目名稱:microMathematics,代碼行數:31,代碼來源:FileUtils.java

示例12: 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

示例13: 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

示例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.getSingleton方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。