【问题标题】:How to open doc/xls/ppt/pdf/dwg in a App?如何在应用程序中打开 doc/xls/ppt/pdf/dwg?
【发布时间】:2016-01-29 04:09:23
【问题描述】:

我想打开一些通用文件,例如 doc/xls/ppt/pdf/dwg,但是我找不到可以执行此操作的视图,通用视图只能打开一两个类型的文件。第三个可以提供帮助吗我来做这件事。安卓:)

【问题讨论】:

  • 使用我的答案寻求帮助 - stackoverflow.com/questions/33820723/…
  • 你也可以使用webview
  • 我尝试使用 webview 打开一个 pdf,但 UI 中没有任何内容,只是空白
  • 显示您的网页浏览代码
  • 感谢您的帮助!他们修改要求。

标签: android


【解决方案1】:

打开doc文件可以使用follow

public class MainActivity extends Activity {



     @Override

     public void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);

      setContentView(R.layout.activity_main);



      Button button = (Button) findViewById(R.id.bPressMe);



      button.setOnClickListener(new OnClickListener() {

       @Override

       public void onClick(View v) {



        File file = new File(Environment.getExternalStorageDirectory(),

          "Help Desk Voice Flow.doc");



        try {

         if (file.exists()) {

          Uri path = Uri.fromFile(file);

          Intent objIntent = new Intent(Intent.ACTION_VIEW);

          // replace "application/msword" with

          // "application/vnd.openxmlformats-officedocument.wordprocessingml.document"

          // for docx files

          // objIntent.setDataAndType(path,"application/msword");

          objIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

          startActivity(objIntent);

         } else {

          Toast.makeText(MainActivity.this, "File NotFound",

            Toast.LENGTH_SHORT).show();

         }

        } catch (ActivityNotFoundException e) {

         Toast.makeText(MainActivity.this,

           "No Viewer Application Found", Toast.LENGTH_SHORT)

           .show();

        } catch (Exception e) {

         e.printStackTrace();

        }

       }

      });



     }

【讨论】:

  • 感谢您的回答,但我必须以一种方式打开所有类型文件。
猜你喜欢
  • 2021-08-27
  • 2018-09-12
  • 1970-01-01
  • 2013-07-14
  • 2014-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-25
相关资源
最近更新 更多