Skip to content

Commit

Permalink
Adopt registerReceiver
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed May 10, 2024
1 parent 9b9babc commit 823836e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.io.OutputStream;
import java.util.Collection;

import android.annotation.SuppressLint;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
Expand Down Expand Up @@ -267,9 +268,16 @@ private boolean tryOpen() {
}
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
private void registerReceiver() {
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
activity_.registerReceiver(this, filter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
activity_.registerReceiver(this, filter, Context.RECEIVER_NOT_EXPORTED);
} else
activity_.registerReceiver(this, filter);
} else
activity_.registerReceiver(this, filter);
}

private void unregisterReceiver() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Collection;
import java.util.HashMap;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
Expand Down Expand Up @@ -484,11 +485,18 @@ private void checkPermission() {
}
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
private void registerReceiver() {
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
activity_.registerReceiver(this, filter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
activity_.registerReceiver(this, filter, Context.RECEIVER_NOT_EXPORTED);
} else
activity_.registerReceiver(this, filter);
} else
activity_.registerReceiver(this, filter);
}

private void unregisterReceiver() {
Expand Down

0 comments on commit 823836e

Please sign in to comment.