androidstudio 打开文件管理器

//点击按钮跳转到文件管理器

Button bt_open=findViewById(R.id.bt_open);
        bt_open.setOnClickListener(new View.OnClickListener() {
            String[] mimeTypes = {MimeType.DOC, MimeType.DOCX, MimeType.PDF, MimeType.PPT, MimeType.PPTX, MimeType.XLS, MimeType.XLSX,MimeType.IMAGE1,MimeType.IMAGE2,MimeType.IMAGE3,MimeType.IMAGE4,MimeType.IMAGE6,MimeType.TEXT,MimeType.IMAGE7};
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
//                if (mimeTypes != null) {
//                    intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
//                }
                intent.setType("*/*");
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                startActivityForResult(intent,1);

            }
        });
// 文件类型的定义
public class MimeType {
    public static final String DOC = "application/msword";
    public static final String DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
    public static final String XLS = "application/vnd.ms-excel";
    public static final String XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    public static final String PPT = "application/vnd.ms-powerpoint";
    public static final String PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
    public static final String PDF = "application/pdf";
    public static final String TEXT = "text/plain";
    public static final String IMAGE6="image/png";
    public static final String IMAGE1="image/jpg";
    public static final String IMAGE2="image/jpeg";
    public static final String IMAGE3="image/gif";
    public static final String IMAGE4="image/bmp";
    public static final String IMAGE7="image/tiff";//tif
//    public static final String IMAGE7="application/tiff";//tif
}
//点击文件所在的类的过滤


    

    
    

    

    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

运行结果:小米,VIVO手机识别不了tif文件,华为可以。所以去除了文件过滤这一条件。

你可能感兴趣的:(移动开发)