我有一个查询。我需要显示 sdcard 特定文件夹的所有内容。我需要做的是告诉用户 sdcard 中的特定目录中没有文件,因此需要打开该文件夹并将其显示在屏幕上。例如。我没有互联网,我们可以显示打开互联网的警报并打开设置屏幕。同样,我也想打开 sdcard/myFolder 屏幕。如果可能在android中,请指导我该怎么做?谢谢大家。
问问题
744 次
1 回答
0
尝试使用以下代码检查目录是否可用并有文件:
String Directory = "";
String[] mFileList ;
//GET ROOT DIRECTORY OF EXTERNAL STORAGE + DIRECTORY THAT YOU WANT
File dir = new File(Environment.getExternalStorageDirectory() + DIRECTORY);
if(dir.exists()) {
mFileList = dir.list(filter);
if(mFileList.length==0)
//Inform that directory is empty
}
else {
//Inform user that there is no such directory
}
然后你可以打开对话框:
Dialog dialog = null;
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_Holo));//this, R.style.AlertDialogCustom));
builder.setTitle("Choose your file");
if(mFileList == null) {
//Log.e(TAG, "Showing file picker before loading the file list");
dialog = builder.create();
}
builder.setItems(mFileList, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mChosenFile = mFileList[which];
//Do something after choosing the file
}
});
dialog = builder.show();
return true;
我希望它会帮助你。
于 2013-06-14T05:11:06.520 回答