2016-04-24 54 views
0

當與下面的方法打開一個文件選擇器:機器人:使可作爲選擇內部文件選擇器

Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
intent.setType("file/*"); 
intent.addCategory(Intent.CATEGORY_OPENABLE); 
Intent chooserIntent = Intent.createChooser(intent, "Open file"); 
startActivityForResult(chooserIntent, REQUEST_CODE_FILE_PICKER); 

除非默認已定,這將呈現給用戶一個選擇的文件選擇器的使用。你如何讓自己的內部文件選擇器作爲提供給用戶的文件選擇器的選擇之一(例如Material File Picker)?

+0

http://developer.android.com/ reference/android/content/Intent.html#EXTRA_INITIAL_INTENTS – CommonsWare

+0

謝謝,我會看看。您是否能夠在此處提供有關相關主題的任何指導:http://stackoverflow.com/q/36821133/4070848? – drmrbrewer

回答

0

感謝@ CommonsWare的評論,這裏是內部文件選擇器添加的選擇呈現給用戶的列表需要額外的代碼位:

// this bit is as before... 
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
intent.setType("file/*"); 
intent.addCategory(Intent.CATEGORY_OPENABLE); 
Intent chooserIntent = Intent.createChooser(intent, "Open file"); 

// new bit... create Intent for the internal file picker... 
Intent materialFilePickerIntent = new Intent(this, FilePickerActivity.class); 
materialFilePickerIntent.putExtra(FilePickerActivity.ARG_FILE_FILTER, Pattern.compile(".*\\.txt$")); 

// and add the picker to the list... 
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { materialFilePickerIntent }); 

// finally, startActivityForResult() as before... 
startActivityForResult(chooserIntent, REQUEST_CODE_FILE_PICKER);