Android is different from the sandbox mode of iOS, you can browse the local memory through the file browser. The Android API also provides the appropriate interface.
The basic idea is to get the URI from the file browser that the Android API calls to the system, and then convert the URI to file to obtain file.
Call the system's own file browser
public class Mainactivity extends appcompatactivity { @Override protected void onCreate (Bundle Savedinstancestate) { Super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_main); Button btn= (button) Findviewbyid (R.ID.BTN); Btn.setonclicklistener (New View.onclicklistener () { @Override public void OnClick (View v) { Intent Intent = new Intent (intent.action_get_content); Intent.settype ("*/*");//set type, I here is any type, any suffix can be written like this. intent.addcategory (intent.category_openable); Startactivityforresult (intent,1);}); }}
Intent.settype ("image/*");//intent.settype ("audio/*"); Select audio//intent.settype ("video/*"); Select Video (mp4 3gp is android supported video format)//intent.settype ("video/*;image/*");//select both video and picture
Callback
@Overrideprotected void Onactivityresult (int requestcode, int resultcode, Intent data) { if (ResultCode = = Activi Ty. RESULT_OK) {//whether or not to choose, not to continue the uri uri = Data.getdata (),//Get the URI, followed by the process of converting the URI into file. string[] proj = {MediaStore.Images.Media.DATA}; Cursor actualimagecursor = Managedquery (URI, proj, NULL, NULL, NULL); int actual_image_column_index = Actualimagecursor.getcolumnindexorthrow (MediaStore.Images.Media.DATA); Actualimagecursor.movetofirst (); String Img_path = actualimagecursor.getstring (actual_image_column_index); File File = new file (Img_path); Toast.maketext (Mainactivity.this, file.tostring (), Toast.length_short). Show ();}}
The Onactivityresult function responds to the action of selecting a file.
Reprinted to: http://www.banbaise.com/archives/614
(GO) Android calls the file Manager that comes with the system to select files and get the path