eddieowens / react-native-boundary

Native implementation of geofencing/region monitoring

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue PendingIntent.FLAG_IMMUTABLE app crashed on Android app Target 31 (Android 12)

thongbbc opened this issue · comments

Hello, we have been having this issue on Android app Target 31.
Ref document: https://stackoverflow.com/questions/67045607/how-to-resolve-missing-pendingintent-mutability-flag-lint-warning-in-android-a

I tried with solution add dependency into build.gradle
implementation 'androidx.work:work-runtime:2.7.1'

But it still does not work.

-> My latest solution to fix this which is using patch package to modify Native code

    private PendingIntent getBoundaryPendingIntent() {
        if (mBoundaryPendingIntent != null) {
            return mBoundaryPendingIntent;
        }
        Intent intent = new Intent(getReactApplicationContext(), BoundaryEventBroadcastReceiver.class);
        mBoundaryPendingIntent = PendingIntent.getBroadcast(getReactApplicationContext(), 0, intent, PendingIntent.
                FLAG_UPDATE_CURRENT);
        return mBoundaryPendingIntent;
    }

Change mBoundaryPendingIntent = PendingIntent.getBroadcast(getReactApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); to

    final int flag =  Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_UPDATE_CURRENT;
        mBoundaryPendingIntent = PendingIntent.getBroadcast(getReactApplicationContext(), 0, intent, flag);

I think we should create PR for this. Thanks.