【问题标题】:How to read/open PPT files in Android?如何在 Android 中读取/打开 PPT 文件?
【发布时间】:2015-04-02 11:49:47
【问题描述】:

[这个问题可能重复,但我找不到我要找的内容]

[阅读]How can we open files like ppt, doc, pps, rtf, etc. in Android?

我有 PPT 文件。在我的应用程序中,我有一个列表视图,其中显示了我的私人应用程序文件夹中可用的 PPT 文件列表。在点击特定文件时,我想在我的应用程序中打开相应的 PPT 文件进行阅读。

我正在创建的 App 就像是 PPT 的集合,并逐一阅读。

请提供任何 API/示例/链接。

【问题讨论】:

    标签: android ms-office powerpoint


    【解决方案1】:

    您需要使用其他应用程序打开您的 ppt 文件,请确保您提供的文件位置可供其他应用程序访问。尝试以下操作:

     final Uri uri = Uri.fromFile(file); 
        final Intent intent = new Intent(Intent.ACTION_VIEW); 
        intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); 
    
        PackageManager pm = getPackageManager();
        List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
        if(list.size() > 0)
           startActivity(context, intent);
    

    可用的应用程序将显示给用户,用户可以选择可以打开的应用程序。

    【讨论】:

    • 有什么方法可以在我的应用程序中打开这些文件。
    • 不,您需要实现整个功能。就像在 windows 中我们使用 office 来打开电子表格和文档一样,我们需要一些提供该功能的应用程序。
    【解决方案2】:
    private void openPPT(final String path) {
        File file = new File(path);
        Uri uri ;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    uri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", file);
                } else {
                    uri = Uri.fromFile(file);
                }
    
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setDataAndType(path, "application/vnd.ms-powerpoint");
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
        try {
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(this, "Application not found", Toast.LENGTH_SHORT).show();
        }
    }
    

    【讨论】:

    • 使用上面的代码对于在android中读取和打开ppt文件很有用,使用fileprovider for Build.VERSION.SDK_INT >= Build.VERSION_CODES.M 在Android Manifext中添加Provider路径。
    猜你喜欢
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多