Http://blog.csdn.net/zqchn/article/details/8770913
The project network disk that is being created these days. When uploading files, you need to call the File Manager that comes with the system to select files. Later, you are considering how to call the files. You have searched the internet for a long time and there is no good solution, later, I found a good article and used the code for reference.
/** Select software to call the file to select the file **/private void showfilechooser () {intent = new intent (intent. action_get_content); intent. settype ("*/*"); intent. addcategory (intent. category_openable); try {startactivityforresult (intent. createchooser (intent, "select a file to upload"), file_select_code);} catch (Android. content. activitynotfoundexception ex) {// potentially direct the user to the market with a dialogtoast. maketext (getactivity (), "Please install file manager", toast. length_short ). show ();}}
In catch, we can do more operations, such as redirecting to a page for downloading the File Manager or so on.
How to handle the returned data. Upload in my project is received as follows
/** Upload operations based on the selected returned file **/@ overridepublic void onactivityresult (INT requestcode, int resultcode, intent data) {// todo auto-generated method stubif (resultcode = activity. result_ OK) {// get the URI of the selected fileuri uri = data. getdata (); string URL; try {url = ffileutils. getpath (getactivity (), Uri); log. I ("ht", "url" + URL); string filename = URL. substring (URL. lastindexof ("/") + 1); intent = new intent (getactivity (), uploadservices. class); intent. putextra ("FILENAME", filename); intent. putextra ("url", URL); intent. putextra ("type", ""); intent. putextra ("fuid", ""); intent. putextra ("type", ""); getactivity (). startservice (intent);} catch (urisyntaxexception e) {// todo auto-generated catch blocke. printstacktrace () ;}} super. onactivityresult (requestcode, resultcode, data );}
---------------------------------------------------------
Private Static final int file_select_code = 0; Private Static final string tag = "videoactivity"; private void choosefile () {intent = new intent (intent. action_get_content); intent. settype ("*/*"); intent. addcategory (intent. category_openable); try {startactivityforresult (intent. createchooser (intent, "select file"), file_select_code);} catch (Android. content. activitynotfoundexception ex) {toast. maketext (Th Is, "You have a file manager -_-!! ", Toast. length_short). Show () ;}@ overridepublic void onactivityresult (INT requestcode, int resultcode, intent data) {// todo auto-generated method stubif (resultcode! = Activity. result_ OK) {log. E (TAG, "onactivityresult () error, resultcode:" + resultcode); super. onactivityresult (requestcode, resultcode, data); return;} If (requestcode = file_select_code) {URI uri = data. getdata (); log. I (TAG, "------->" + Uri. getpath ();} super. onactivityresult (requestcode, resultcode, data );}