Skip to content

Commit

Permalink
Merge pull request #110 from Foxushka/android-14-fix
Browse files Browse the repository at this point in the history
fix: Android 14 compability
  • Loading branch information
altera2015 authored May 11, 2024
2 parents a403a7b + 5c2820f commit c62717e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion android/src/main/java/dev/bessems/usbserial/UsbSerialPlugin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.bessems.usbserial;

import android.annotation.SuppressLint;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
Expand All @@ -13,6 +14,7 @@

import com.felhr.usbserial.UsbSerialDevice;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
Expand Down Expand Up @@ -105,6 +107,7 @@ private interface AcquirePermissionCallback {
void onSuccess(UsbDevice device);
void onFailed(UsbDevice device);
}
@SuppressLint("PrivateApi")
private void acquirePermissions(UsbDevice device, AcquirePermissionCallback cb) {

class BRC2 extends BroadcastReceiver {
Expand Down Expand Up @@ -148,7 +151,19 @@ public void onReceive(Context context, Intent intent) {
flags = PendingIntent.FLAG_MUTABLE;
}

PendingIntent permissionIntent = PendingIntent.getBroadcast(cw, 0, new Intent(ACTION_USB_PERMISSION), flags);
Intent intent = new Intent(ACTION_USB_PERMISSION);

Class<?> activityThread = null;
try {
activityThread = Class.forName("android.app.ActivityThread");
Method method = activityThread.getDeclaredMethod("currentPackageName");
String appPackageName = (String) method.invoke(activityThread);
intent.setPackage(appPackageName);
} catch (Exception e) {
// Not too important to throw anything
}

PendingIntent permissionIntent = PendingIntent.getBroadcast(cw, 0, intent, flags);

IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);

Expand Down

0 comments on commit c62717e

Please sign in to comment.