我有一个查询。我需要显示sdcard特定文件夹的所有内容。我需要做的是我需要告诉用户sdcard中的特定目录中没有文件,因此需要打开该文件夹并在屏幕上显示。例如。我没有互联网,我们可以显示打开互联网的警报,也打开设置屏幕。同样的方式我也想打开sdcard / myFolder屏幕。请指导我如果可以在android中做什么? 提前谢谢大家。
答案 0 :(得分: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;
我希望它会对你有所帮助。