2
我用import java.io.File;
從我的SD卡導入所有音樂文件, 現在我想要使用Mediastore的文件的標題,但我該怎麼做? 這是我現在使用的代碼。從文件中獲取媒體標題
public class ListFiles extends ListActivity {
private List<String> directoryEntries = new ArrayList<String>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
File directory = new File(i.getStringExtra("directory"));
if (directory.isDirectory()){
File[] files = directory.listFiles();
Arrays.sort(files, new Comparator<File>(){
public int compare(File f1, File f2) {
return -Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
}
});
this.directoryEntries.clear();
for (File file : files) {
this.directoryEntries.add(file.getName());
}
ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this,R.layout.file_row, this.directoryEntries);
this.setListAdapter(directoryList);
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
File clickedFile = new File(this.directoryEntries.get(position));
Intent i = getIntent();
i.putExtra("clickedFile", clickedFile.toString());
setResult(RESULT_OK, i);
finish();
}
}
感謝。
,你可以檢查這個問題https://stackoverflow.com/questions/48934159/mediastore-not-working- when-folder-programmatically-created我需要幫助 –