java - 上传文件功能,选择本地文件action
阿神
阿神 2017-04-18 09:17:27
0
1
518

最近在做一个即时通讯,选择文件上传功能.
当我点击按钮选择要上传的文件时的action,使用

 Intent i=new Intent();
        i.setAction(Intent.ACTION_GET_CONTENT);
        i.setType("*/*");
        startActivityForResult(i,20);
        
    这样可以打开文件管理器,但是一直很不懂setType
    setType("image/*");  是打开图片文件
    setType(“audio/*”); 是打开音频
    问题是:
    setType("*/*");  是打开所有类型的文件吗?
    setType("file/*");  要怎么理解?
    
    在onActivityResult返回值中我需要获取到点击文件的路径用于上传文件,如何获取?,希望有大神指点指点
       
阿神
阿神

闭关修行中......

reply all(1)
左手右手慢动作

For what value to set for setType, you have to look at Android MIME first, and you will know what type should be passed accordingly. There is no "file/" type in MIME. "*/*" refers to all MIME files. The return value of onActivityResult contains Intent data, through which you can obtain the file path you selected.

Uri uri = data.getData();
String path = uri.getPath();
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template