/* 在手机上打开文件的method */
private void openFile(File f)
{
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
/* 调用getMIMEType()来取得MimeType */
String type = getMIMEType(f);
/* 设置intent的file与MimeType */
intent.setDataAndType(Uri.fromFile(f),type);
startActivity(intent);
}
/* 判断文件MimeType的method */
private String getMIMEType(File f)
{
String type="";
String fName=f.getName();
/* 取得扩展名 */
String end=fName.substring(fName.lastIndexOf(".")
+1,fName.length()).toLowerCase();
/* 依扩展名的类型决定MimeType */
if(end.equals("m4a")||end.equals("mp3")||end.equals("mid")||
end.equals("xmf")||end.equals("ogg")||end.equals("wav"))
{
type = "audio";
}
else if(end.equals("3gp")||end.equals("mp4"))
{
type = "video";
}
else if(end.equals("jpg")||end.equals("gif")||end.equals("png")||
end.equals("jpeg")||end.equals("bmp"))
{
type = "image";
}
else if(end.equals("apk"))
{
/* android.permission.INSTALL_PACKAGES */
type = "application/vnd.android.package-archive";
}
else
{
type="*";
}
/*如果无法直接打开,就跳出软件列表给用户选择 */
if(end.equals("apk"))
{
}
else
{
type += "/*";
}
return type;
}
这是个通用的方法,用来打开任意类型文件
分享到:
相关推荐
自己设计的“指定打开(存储)文件(夹)”程序,可供其他程序调用。
Android文件选择器,可以实现多选,单选文件。
Unity 调用Android文件资源管理器,可以选择Android手机上的图片,视频等一些列文件,并且获得相关的文件路径。直接导入Unity即可运行。测试已经通过
基于Android的手机文件扫描 可以扫面出所有的txt文件 并且可以打开
一个android对话框,最终会返回文件的地址,
android根据文件类型自动打开相应应用程序的代码
Android7.0 Intent打开文件管理器 获取文件真实路径。虽然网上很多demo,但是没有一个能够兼容所有Android机的,去网上学习了然后自己亲测过手机分别有Android7.0/6.0/4.3个版本。
修改flcop提供的代码,以适应Delphi xe10环境,版权归flcop所有
前人 Delphi XE5 Android Dialogs 对话框,升级到XE10,需要修改一些地方,才能编译通过,尽量不让人走弯路,而且积分也少很多
* 打开文件 * @param file */ private void openFile(File file){ Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //设置intent的Action属性 intent.setAction...
android用于打开各种文件的intent
利用Android原生API打开文件demo
Android 中打开pdf文件也是一种很常见的场景,本文主要介绍了Android打开本地pdf文件的方法。具有很好的参考价值。下面跟着小编一起来看下吧
android 系统调用WPS打开word excel ppt pdf 等,将代码类移入的你项目,有对6.0 7.0及以上系统做文件读取方法
对话框以列表形式显示文件目录 选择文件完成后返回文件的路径
工程可以正常打开,单击一个按钮会弹出一个文件对话框,然后选择目录查找相应的文件。可以下载后参考下
Android 插件式打开PDF文件
基本思路,先通过Android API调用系统自带的文件浏览器选取文件获得URI,然后将URI转换成file,从而得到file。
这个是网上找到的Android打开ppt的demo,运行能成功,里面有个example.pptx的文件,只为收藏而上传的