Validating and reading a Word file in Android

前端 未结 6 1794
忘了有多久
忘了有多久 2020-12-05 16:19

I want to be able to access a word file in the sdcard of the user\'s phone, and the file will be chosen by the user. I want to be able to process the file, i.e. read its con

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 16:52

    so, as i write above. The simpliest way to check if it's word-file (.doc) is to get it's absolute path and check it with path.endsWith(".doc");

    Android doesn't have default app to view .doc-files, but if user has installed such an app (i.e. Polaris Office), you can view it in this way:

    //Uri uri = Uri.parse("file://"+file.getAbsolutePath());
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    String type = "application/msword";
    intent.setDataAndType(Uri.fromFile(file), type);
    startActivity(intent);  
    

提交回复
热议问题