Android通过文件类型打开系统已有支持程序开启

来源:互联网 发布:mac文件批量重命名 编辑:程序博客网 时间:2024/06/05 19:10

平时,在我们自己的应用内实现点击文件弹窗让我们选择打开方式的功能,很简单,就是调用系统Intent,以下就是

相应代码,希望有所帮助:   

File file = new File(path//文件路径);
if (file.exists()) {    
    Uri path = Uri.fromFile(file);    
    Intent intent = new Intent(Intent.ACTION_VIEW);    
    intent.setDataAndType(path, "text/plain");    
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);    
    startActivity(intent);
}else{       Toast.makeText(getContext(), "文件不存在或已被删除", Toast.LENGTH_SHORT).show();}

原创粉丝点击