Mam dokładnie kopiowane następujący fragment kodu z wcześniejszym delegowania i działa na symulatorze, a także w moim urządzeniu Nexus 9, aż do punktu!ACTION otwarty dokument TREE zwraca tylko puste ostatnich folderowi
Jednak wszystkie uzyskać jest pusty Nowy folder, a ja nigdy nie dotrzeć do kodu, który zapisuje plik.
Co należy zmienić, aby uzyskać prawidłowe drzewo dokumentu?
private void testDocumentTree() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, 42);
}
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
String TAG = "onActivityResult";
if (resultCode == RESULT_OK) {
Uri treeUri = resultData.getData();
DocumentFile pickedDir = DocumentFile.fromTreeUri(this, treeUri);
// List all existing files inside picked directory
for (DocumentFile file : pickedDir.listFiles()) {
Log.d(TAG, "Found file " + file.getName() + " with size " + file.length());
}
// Create a new file and write into it
DocumentFile newFile = pickedDir.createFile("text/plain", "My Novel");
try {
OutputStream out = getContentResolver().openOutputStream(newFile.getUri());
out.write("A long time ago...".getBytes());
out.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File Not Found, reason: ", e);
} catch (IOException e) {
Log.d(TAG,"IOException, reason: ", e);
}
}
}
FWIW dodałem problem tutaj: https://code.google.com/p/android/issues/detail?id=202116 –