Intent打开其它文件的使用
来源:互联网 发布:广州程序员工资水平 编辑:程序博客网 时间:2024/06/07 01:13
public class OpenFileUtils {
public static Intent openFile(String filePath) {
File file = new File(filePath);
if (!file.exists())
return null;
/* 取得扩展名 */
String end = file
.getName()
.substring(file.getName().lastIndexOf(".") + 1,
file.getName().length()).toLowerCase();
/* 依扩展名的类型决定MimeType */
if (end.equals("jpg") || end.equals("gif") || end.equals("png")
|| end.equals("jpeg") || end.equals("bmp")) {
return getImageFileIntent(filePath);
} else if (end.equals("ppt") || end.equals("pptx")) {
return getPptFileIntent(filePath);
} else if (end.equals("xls") || end.equals("xlsx")) {
return getExcelFileIntent(filePath);
} else if (end.equals("doc") || end.equals("docx")) {
return getWordFileIntent(filePath);
} else if (end.equals("pdf")) {
return getPdfFileIntent(filePath);
} else if (end.equals("mp4")) {
return getVideoFileIntent(filePath);
} else if (end.equals("apk")) {
return getApkFileIntent(filePath);
} else {
return getAllIntent(filePath);
}
}
// Android获取一个用于打开APK文件的intent
public static Intent getAllIntent(String param) {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "*/*");
return intent;
}
// Android获取一个用于打开图片文件的intent
public static Intent getImageFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "image/*");
return intent;
}
// Android获取一个用于打开PPT文件的intent
public static Intent getPptFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
return intent;
}
// Android获取一个用于打开Excel文件的intent
public static Intent getExcelFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "application/vnd.ms-excel");
return intent;
}
// Android获取一个用于打开Word文件的intent
public static Intent getWordFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "application/msword");
return intent;
}
// Android获取一个用于打开PDF文件的intent
public static Intent getPdfFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "application/pdf");
return intent;
}
// Android获取一个用于打开PDF文件的intent
public static Intent getVideoFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "video/*");
return intent;
}
// Android获取一个用于打开PDF文件的intent
public static Intent getApkFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "application/vnd.android.package-archive");
return intent;
}
}
public static Intent openFile(String filePath) {
File file = new File(filePath);
if (!file.exists())
return null;
/* 取得扩展名 */
String end = file
.getName()
.substring(file.getName().lastIndexOf(".") + 1,
file.getName().length()).toLowerCase();
/* 依扩展名的类型决定MimeType */
if (end.equals("jpg") || end.equals("gif") || end.equals("png")
|| end.equals("jpeg") || end.equals("bmp")) {
return getImageFileIntent(filePath);
} else if (end.equals("ppt") || end.equals("pptx")) {
return getPptFileIntent(filePath);
} else if (end.equals("xls") || end.equals("xlsx")) {
return getExcelFileIntent(filePath);
} else if (end.equals("doc") || end.equals("docx")) {
return getWordFileIntent(filePath);
} else if (end.equals("pdf")) {
return getPdfFileIntent(filePath);
} else if (end.equals("mp4")) {
return getVideoFileIntent(filePath);
} else if (end.equals("apk")) {
return getApkFileIntent(filePath);
} else {
return getAllIntent(filePath);
}
}
// Android获取一个用于打开APK文件的intent
public static Intent getAllIntent(String param) {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "*/*");
return intent;
}
// Android获取一个用于打开图片文件的intent
public static Intent getImageFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "image/*");
return intent;
}
// Android获取一个用于打开PPT文件的intent
public static Intent getPptFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
return intent;
}
// Android获取一个用于打开Excel文件的intent
public static Intent getExcelFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "application/vnd.ms-excel");
return intent;
}
// Android获取一个用于打开Word文件的intent
public static Intent getWordFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "application/msword");
return intent;
}
// Android获取一个用于打开PDF文件的intent
public static Intent getPdfFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "application/pdf");
return intent;
}
// Android获取一个用于打开PDF文件的intent
public static Intent getVideoFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "video/*");
return intent;
}
// Android获取一个用于打开PDF文件的intent
public static Intent getApkFileIntent(String param) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, "application/vnd.android.package-archive");
return intent;
}
}
0 0
- Intent打开其它文件的使用
- 使用Intent调用系统其它程序打开本地各种类型的文件
- Android打开文件的Intent及使用
- 打开文件的Intent及使用
- Android--打开文件的Intent及使用
- android 打开文件的Intent及使用
- Android 文件打开的intent
- 打开各种文件的intent
- 打开不同文件的Intent
- Android杂谈--打开文件的Intent及使用
- Android杂谈--打开文件的Intent及使用
- Android杂谈--打开文件的Intent及使用
- Android杂谈--打开文件的Intent及使用
- Android杂谈--打开文件的Intent及使用
- Android开发打开文件的Intent及使用
- Android杂谈--打开文件的Intent及使用
- Android开发打开文件的Intent及使用
- [小代码]使用intent用默认的程序打开文件
- rabbitMQ重启提示发生系统错误 5。 拒绝访问。
- Bolt的生命周期
- ckeditor 中文api
- iOS6新特征:UICollectionView介绍
- 慕课第四次学习总结
- Intent打开其它文件的使用
- 写入Memcache时是否应该压缩值?
- HTTP请求出错(no resource): Android4.0不能在主线程中进行HTTP请求
- linux C 遍历目录及其子目录 opendir -> readdir -> closedir .
- angular学习
- android 真机调试步骤
- CMake的作用
- php实现的支持断点续传的文件下载类
- 评价星星点击效果