当前位置: 首页>>代码示例>>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;未经允许,请勿转载。