Может кто-нибудь ответить, почему я получил это исключение при попытке получить mediaUri из documentUri. Я хочу запросить ContentResolver с mediaUri, чтобы получить все аудиофайлы из внешнего хранилища
Uri mediaUri = MediaStore.getMediaUri(mContext,docUri);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult Result erreicht " + requestCode);
if (requestCode != PICK_AUDIO_REQUEST || resultCode != RESULT_OK) {
Log.d(TAG, "no selection");
return;
}
mUri = data.getData();
getContentResolver().takePersistableUriPermission(mUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(mUri,
DocumentsContract.getTreeDocumentId(mUri));
docUri = DocumentsContract.buildDocumentUriUsingTree(mUri,
DocumentsContract.getTreeDocumentId(mUri));
Uri mediaUri = MediaStore.getMediaUri(mContext, docUri);
}
mUri: content://com.android.providers.downloads.documents/tree/downloads
docUri: content://com.android.providers.downloads.documents/tree/downloads/document/downloads
Stacktrace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cl.languagetranslation.testandroid10, PID: 29419
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=3, result=-1, data=Intent { dat=content://com.android.providers.downloads.documents/tree/downloads flg=0xc3 }} to activity {com.cl.languagetranslation.testandroid10/com.cl.languagetranslation.testandroid10.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getPath()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4845)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getPath()' on a null object reference
at android.os.Parcel.createException(Parcel.java:2077)
at android.os.Parcel.readException(Parcel.java:2039)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:658)
at android.content.ContentProviderClient.call(ContentProviderClient.java:558)
at android.content.ContentProviderClient.call(ContentProviderClient.java:546)
at android.provider.MediaStore.getMediaUri(MediaStore.java:3501)
at com.cl.languagetranslation.testandroid10.MainActivity.onActivityResult(MainActivity.java:121)
at android.app.Activity.dispatchActivityResult(Activity.java:8110)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Спасибо за помощь! Получить аудиофайлы из хранилища - действительно тяжелая работа ... есть и другие, которые тоже борются ... так что я не один, пытаюсь это сделать ...
GGK