我想打开一些Common文件,比如doc / xls / ppt / pdf / dwg,但我找不到一个可以做到这一点的视图,普通视图只打开一个或两个类型文件。第三个可以帮助我这样做。 Android:)
答案 0 :(得分:0)
打开doc文件,您可以按照
使用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();
}
}
});
}