如何在Android中阅读/打开PPT文件?

问题描述 投票:1回答:2

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

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

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

我正在创建的应用程序就像PPT的集合并逐一阅读它们。

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

android ms-office powerpoint
2个回答
3
投票

您需要使用其他应用程序打开您的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);

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


0
投票
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();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.