Skip to content

Commit

Permalink
Merge pull request #2 from pretix-unofficial/sdk34-intents
Browse files Browse the repository at this point in the history
Fix USB device intents for SDK34+
  • Loading branch information
robbi5 authored Aug 20, 2024
2 parents b40fb14 + b417bcc commit ad0ee92
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions libuvccamera/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
}

defaultConfig {
minSdkVersion 14
minSdkVersion 19
targetSdkVersion versionTarget
}

Expand Down 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
2 changes: 1 addition & 1 deletion usbCameraCommon/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
}

defaultConfig {
minSdkVersion 18
minSdkVersion 19
targetSdkVersion versionTarget

}
Expand Down

0 comments on commit ad0ee92

Please sign in to comment.