判断是否属于图片类型
public static boolean isImageType(String path) {
Drawable drawable = Drawable.createFromPath(path);
if (drawable != null) {
return true;
}
return false;
}
判断是否属于video类型
public static boolean isVideoType(String path) {
if (path.endsWith(".mp4") || path.endsWith(".avi") || path.endsWith(".mov") || path.endsWith(".rmvb")
|| path.endsWith(".mkv") || path.endsWith(".wmv"))
return true;
return false;
}
打开图片(调用系统)
public static voidopenImageFile(Context context,String path) {
Intent intent =newIntent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(newFile(path));
intent.setDataAndType(uri,"image/*");
context.startActivity(intent);
}
打开video(调用系统)
public static voidopenVideoFile(Context context,String path) {
Intent intent =newIntent("android.intent.action.VIEW");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("oneshot",0);
intent.putExtra("configchange",0);
Uri uri = Uri.fromFile(newFile(path));
intent.setDataAndType(uri,"video/*");
context.startActivity(intent);
}