Skip to content

Commit

Permalink
Fix USB device intents for SDK34+
Browse files Browse the repository at this point in the history
  • Loading branch information
robbi5 committed Aug 19, 2024
1 parent b40fb14 commit e3f89d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion libuvccamera/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ dependencies {
implementation fileTree(dir: new File(buildDir, 'libs'), include: '*.jar')

implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.annotation:annotation:1.6.0'
implementation 'androidx.core:core:1.13.1'
implementation 'androidx.annotation:annotation:1.8.2'

implementation("com.serenegiant:common:${commonLibVersion}") {
exclude module: 'support-v4'
Expand Down
13 changes: 7 additions & 6 deletions libuvccamera/src/main/java/com/serenegiant/usb/USBMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
import android.util.Log;
import android.util.SparseArray;

import androidx.core.app.PendingIntentCompat;
import androidx.core.content.ContextCompat;

import com.serenegiant.utils.HandlerThreadHandler;

public final class USBMonitor {
Expand Down Expand Up @@ -167,15 +170,13 @@ public synchronized void register() throws IllegalStateException {
if (DEBUG) Log.i(TAG, "register:");
final Context context = mWeakContext.get();
if (context != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE);
} else {
mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0);
}
Intent intent = new Intent(ACTION_USB_PERMISSION);
intent.setPackage(context.getPackageName());
mPermissionIntent = PendingIntentCompat.getBroadcast(context, 0, intent, 0, true);
final IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
// ACTION_USB_DEVICE_ATTACHED never comes on some devices so it should not be added here
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
context.registerReceiver(mUsbReceiver, filter);
ContextCompat.registerReceiver(context, mUsbReceiver, filter, ContextCompat.RECEIVER_EXPORTED);
}
// start connection check
mDeviceCounts = 0;
Expand Down

0 comments on commit e3f89d6

Please sign in to comment.