0
我嘗試使用Cursor查找創建的XML文件的content:// adres。如果文件夾包含1個元素,則XML文件將返回id = 0
我這樣做與下面的代碼:
public static String xmlFilePath = Environment.getExternalStorageDirectory() + "/" + WiFiTransferService.FileServerAsyncTask.context.getPackageName()+ "/" + "variables" + ".xml";
Cursor cursor = getContentResolver().query(
mFilesUri,
new String[]{MediaStore.Files.FileColumns._ID},
MediaStore.Files.FileColumns.DATA + "=?",
new String[]{xmlFilePath}, null);
if (cursor != null && cursor.moveToFirst()) {
id = cursor.getInt(cursor
.getColumnIndex(MediaStore.Files.FileColumns._ID));
}
if (cursor != null) {
cursor.close();
}
的問題是,我得到0 ID,而我在一個文件夾中的文件,並得到正確的ID(如3268),當我有2個或多個文件。相當奇怪的行爲,我不知道是什麼原因造成的。