가능한 중복 : 나는 안드로이드 응용 프로그램을 개발하고하고 싶습니다
Reading an .xml file from sdcard: 어떻게 (내 파일)에서 XML 파일이나/MNT/SDCARD를 선택합니다
사용자가 로컬 장치에서 XML 파일을 업로드 할 수 있도록 허용합니다. 사용자가/sdcard에서 시작하는 장치 파일을 탐색 할 수있게하려고합니다. 이렇게 도와 주시겠습니까?
미리 감사드립니다.
가능한 중복 : 나는 안드로이드 응용 프로그램을 개발하고하고 싶습니다
Reading an .xml file from sdcard: 어떻게 (내 파일)에서 XML 파일이나/MNT/SDCARD를 선택합니다
사용자가 로컬 장치에서 XML 파일을 업로드 할 수 있도록 허용합니다. 사용자가/sdcard에서 시작하는 장치 파일을 탐색 할 수있게하려고합니다. 이렇게 도와 주시겠습니까?
미리 감사드립니다.
private File path = new File(Environment.getExternalStorageDirectory() + "");
private void loadFileList() {
try {
path.mkdirs();
} catch (SecurityException e) {
Log.e(TAG, "unable to write on the sd card ");
}
if (path.exists()) {
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String fn) {
File sel = new File(dir, fn);
if (sel.isDirectory() && !sel.isHidden()) {
int jjj = sel.list().length;
if (jjj >= 1)
return true;
else
return false;
} else if (sel.isFile() && !sel.isHidden()) {
boolean b = fn.endsWith(".xml");
return b;
} else {
return false;
}
}
};
String[] fList = path.list(filter);
fileList = new Item[fList.length];
for (int i = 0; i < fList.length; i++) {
fileList[i] = new Item(fList[i], R.drawable.file_icon);
File sel = new File(path, fList[i]);
if (sel.isDirectory()) {
fileList[i].icon = R.drawable.directory_icon;
Log.d("DIRECTORY", fileList[i].file);
} else {
Log.d("FILE", fileList[i].file);
}
}
if (!firstLvl) {
Item temp[] = new Item[fileList.length + 1];
for (int i = 0; i < fileList.length; i++) {
temp[i + 1] = fileList[i];
}
temp[0] = new Item("Up", R.drawable.directory_up);
fileList = temp;
}
} else {
Log.e(TAG, "path does not exist");
}
adapter = new ArrayAdapter<Item>(this,
android.R.layout.select_dialog_item, android.R.id.text1,
fileList) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// creates view
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view
.findViewById(android.R.id.text1);
// put the image on the text view
textView.setCompoundDrawablesWithIntrinsicBounds(
fileList[position].icon, 0, 0, 0);
// add margin between image and text (support various screen
// densities)
int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
textView.setCompoundDrawablePadding(dp5);
return view;
}
};
}
// Don't Forget To Add Permission for SD Card
롤 당신은 당신의 사본과 그를 혼동하고 –
의 SD 카드에있는 파일의 전체 목록을 붙여 넣을 것이다 – sravan
나는 그것을 지금 시험해보고있다, thanks sravan kumar! –
도움이 될 것입니다. http://stackoverflow.com/questions/3592717/choose-file-dialog – 1615903
Thanks Avadhani! 나는 그것을 검사 할 것이다;) –
고맙습니다 user1615903! 나는 그것을 또한 검사 할 것이다;) –