首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我需要在我的应用程序中的quickoffice中打开我的.doc文件,而不需要寻找合适的应用程序(选项)。

我需要在我的应用程序中的quickoffice中打开我的.doc文件,而不需要寻找合适的应用程序(选项)。
EN

Stack Overflow用户
提问于 2014-06-14 07:38:08
回答 2查看 394关注 0票数 0

我需要打开我的.doc文件在quickoffice在我的应用程序,而不是寻找合适的应用程序(选项)。

我用过这个

代码语言:javascript
复制
    Intent intent = new Intent();

    intent.setAction(android.content.Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(file);
    //String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
    //      MimeTypeMap.getFileExtensionFromUrl(uri.toString()));
    //intent.setDataAndType(uri, type == null ? "*/*" : type);
    intent.setDataAndType(uri, "application/msword");

    startActivity((Intent.createChooser(intent,
            getString(R.string.open_using))));

这个代码显示了我实际上不需要的合适的目标应用程序

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-06-16 13:12:09

对我起作用了。

代码语言:javascript
复制
        PackageManager packageManager = getPackageManager();
        Intent quickOffice = packageManager
            .getLaunchIntentForPackage("com.quickoffice.android");

        File sdcard = Environment.getExternalStorageDirectory();
        //your file location
        File file = new File(sdcard, "Meta Data.doc");
        Uri path = Uri.fromFile(file);

        quickOffice.setAction(Intent.ACTION_VIEW);
        quickOffice.setDataAndType(path, "application/msword");// ---->application/msword

        startActivity(quickOffice);
票数 0
EN

Stack Overflow用户

发布于 2014-06-14 07:43:01

删除createChooser调用,然后将意图传递给startActivity。然后它将打开mime类型的默认应用程序,前提是设置了一个。如果没有设置,它可能仍然会在那些声称可以打开它的应用程序中弹出一个选择器。如果您只想打开快速办公室,您可以通过活动名称来打开它,但是如果没有安装快速办公室,它就会失败(并可能引发异常)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24217713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档