diff --git a/app/src/full/java/org/fdroid/fdroid/nearby/TreeUriScannerIntentService.java b/app/src/full/java/org/fdroid/fdroid/nearby/TreeUriScannerIntentService.java index a0750c838..441fc10e2 100644 --- a/app/src/full/java/org/fdroid/fdroid/nearby/TreeUriScannerIntentService.java +++ b/app/src/full/java/org/fdroid/fdroid/nearby/TreeUriScannerIntentService.java @@ -74,6 +74,11 @@ public class TreeUriScannerIntentService extends IntentService { public static final String TAG = "TreeUriScannerIntentSer"; private static final String ACTION_SCAN_TREE_URI = "org.fdroid.fdroid.nearby.action.SCAN_TREE_URI"; + /** + * @see DocumentsContract.EXTERNAL_STORAGE_PROVIDER_AUTHORITY + * @see ExternalStorageProvider.AUTHORITY + */ + public static final String EXTERNAL_STORAGE_PROVIDER_AUTHORITY = "com.android.externalstorage.documents"; public TreeUriScannerIntentService() { super("TreeUriScannerIntentService"); diff --git a/app/src/full/java/org/fdroid/fdroid/nearby/UsbDeviceAttachedReceiver.java b/app/src/full/java/org/fdroid/fdroid/nearby/UsbDeviceAttachedReceiver.java index b253f7f87..1eccc2d10 100644 --- a/app/src/full/java/org/fdroid/fdroid/nearby/UsbDeviceAttachedReceiver.java +++ b/app/src/full/java/org/fdroid/fdroid/nearby/UsbDeviceAttachedReceiver.java @@ -19,25 +19,19 @@ package org.fdroid.fdroid.nearby; -import android.app.Activity; import android.content.BroadcastReceiver; -import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.content.UriPermission; import android.database.ContentObserver; import android.hardware.usb.UsbManager; import android.net.Uri; import android.os.Build; -import android.os.Bundle; import android.os.Handler; -import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; import android.text.TextUtils; import android.util.Log; -import org.fdroid.fdroid.views.main.MainActivity; +import androidx.annotation.RequiresApi; import org.fdroid.fdroid.views.main.NearbyViewBinder; diff --git a/app/src/full/java/org/fdroid/fdroid/views/main/NearbyViewBinder.java b/app/src/full/java/org/fdroid/fdroid/views/main/NearbyViewBinder.java index 4bc2ab5bf..5d29e0c2f 100644 --- a/app/src/full/java/org/fdroid/fdroid/views/main/NearbyViewBinder.java +++ b/app/src/full/java/org/fdroid/fdroid/views/main/NearbyViewBinder.java @@ -13,6 +13,7 @@ import android.os.Build; import android.os.Environment; import android.os.storage.StorageManager; import android.os.storage.StorageVolume; +import android.provider.DocumentsContract; import android.text.TextUtils; import android.util.Log; import android.view.View; @@ -21,11 +22,9 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; - import androidx.annotation.RequiresApi; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; - import org.fdroid.fdroid.R; import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.nearby.SDCardScannerService; @@ -61,6 +60,8 @@ import java.util.List; * * @see TreeUriScannerIntentService * @see org.fdroid.fdroid.nearby.SDCardScannerService + *
+ * TODO use {@link StorageManager#registerStorageVolumeCallback(Executor, StorageManager.StorageVolumeCallback)} */ public class NearbyViewBinder { public static final String TAG = "NearbyViewBinder"; @@ -165,11 +166,26 @@ public class NearbyViewBinder { for (final StorageVolume storageVolume : storageManager.getStorageVolumes()) { if (storageVolume.isRemovable() && !storageVolume.isPrimary()) { Log.i(TAG, "StorageVolume: " + storageVolume); - final Intent intent = storageVolume.createAccessIntent(null); - if (intent == null) { + Intent tmpIntent = null; + if (Build.VERSION.SDK_INT < 29) { + tmpIntent = storageVolume.createAccessIntent(null); + } else { + tmpIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); + tmpIntent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, + Uri.parse("content://" + + TreeUriScannerIntentService.EXTERNAL_STORAGE_PROVIDER_AUTHORITY + + "/tree/" + + storageVolume.getUuid() + + "%3A/document/" + + storageVolume.getUuid() + + "%3A")); + } + if (tmpIntent == null) { Utils.debugLog(TAG, "Got null Storage Volume access Intent"); return; } + final Intent intent = tmpIntent; + storageVolumeText.setVisibility(View.VISIBLE); String text = storageVolume.getDescription(context);