背景:
我在做一个文件浏览器,基本的浏览已经写好,现在就是需要点到具体类型的文件的时候,比如TXT,就来打开本地能阅读TXT文件的APP,图片就调用能打开能看图片的APP,应该明白我的意思了吧。
我自己的理解:
这里应该是在intent.setAction()
里面写东西吧??
但是我不知道写什么。
intent 有显式启动和隐式启动,这里因该需要隐式的吧。
如果你们知道打开其他任意类型的,你们可以给我写一点,谢谢。
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "text/plain");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
确保你的机器上装有可以打开text的软件,最好try catch一下上面的代码块。