Android日常--文件操作
发布网友
发布时间:2023-05-02 21:29
我来回答
共1个回答
热心网友
时间:2023-05-18 03:02
public static boolean isImageType(String path) {
Drawable drawable = Drawable.createFromPath(path);
if (drawable != null) {
return true;
}
return false;
}
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);
}
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);
}