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


Java Intent.normalizeMimeType方法代碼示例

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


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

示例1: createViewIntentForDownloadItem

import android.content.Intent; //導入方法依賴的package包/類
/**
 * Creates an Intent to open the file in another app by firing an Intent to Android.
 * @param fileUri  Uri pointing to the file.
 * @param mimeType MIME type for the file.
 * @return Intent that can be used to start an Activity for the file.
 */
public static Intent createViewIntentForDownloadItem(Uri fileUri, String mimeType) {
    Intent fileIntent = new Intent(Intent.ACTION_VIEW);
    String normalizedMimeType = Intent.normalizeMimeType(mimeType);
    if (TextUtils.isEmpty(normalizedMimeType)) {
        fileIntent.setData(fileUri);
    } else {
        fileIntent.setDataAndType(fileUri, normalizedMimeType);
    }
    fileIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    fileIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return fileIntent;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:19,代碼來源:DownloadUtils.java

示例2: openFile

import android.content.Intent; //導入方法依賴的package包/類
/**
 * Opens a file in Chrome or in another app if appropriate.
 * @param file path to the file to open.
 * @param mimeType mime type of the file.
 * @param isOffTheRecord whether we are in an off the record context.
 * @return whether the file could successfully be opened.
 */
public static boolean openFile(File file, String mimeType, boolean isOffTheRecord) {
    Context context = ContextUtils.getApplicationContext();
    Intent viewIntent = createViewIntentForDownloadItem(Uri.fromFile(file), mimeType);
    DownloadManagerService service = DownloadManagerService.getDownloadManagerService(context);

    // Check if Chrome should open the file itself.
    if (service.isDownloadOpenableInBrowser(isOffTheRecord, mimeType)) {
        // Share URIs use the content:// scheme when able, which looks bad when displayed
        // in the URL bar.
        Uri fileUri = Uri.fromFile(file);
        Uri shareUri = getUriForItem(file);
        String normalizedMimeType = Intent.normalizeMimeType(mimeType);

        Intent intent =
                getMediaViewerIntentForDownloadItem(fileUri, shareUri, normalizedMimeType);
        IntentHandler.startActivityForTrustedIntent(intent, context);
        return true;
    }

    // Check if any apps can open the file.
    try {
        context.startActivity(viewIntent);
        return true;
    } catch (ActivityNotFoundException e) {
        // Can't launch the Intent.
        Toast.makeText(context, context.getString(R.string.download_cant_open_file),
                     Toast.LENGTH_SHORT)
                .show();
        return false;
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:39,代碼來源:DownloadUtils.java


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