Android日常--文件操作

判断是否属于图片类型

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);

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,498评论 0 17
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,853评论 18 139
  • ¥开启¥ 【使用jni实现Tost】 〖2017-08-20 22:15:04〗 《在xx.cpp中写入以下代码€...
    小菜c阅读 898评论 0 1
  • 环信官方Demo源码分析及SDK简单应用 环信官方Demo源码分析及SDK简单应用-ChatDemoUI3.0 环...
    imGeek阅读 1,582评论 0 3
  • 书籍提供了大量的精神食粮给我,阅读伴随我成长,阅读于我从来都是喂养者与享用的关系。 我爱阅读可以追溯到小学时代。作...
    悠云小筑阅读 362评论 0 1