Skip to content

Commit

Permalink
fix(Android): Fix Android 14 crash with implicit intent (#208)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `targetSdkVersion` is now required to be 34+ for Android users.

---------

Co-authored-by: Ty. Trương Văn <tytv@vng.com.vn>
  • Loading branch information
devtyty and Ty. Trương Văn committed Jun 17, 2024
1 parent 5653969 commit d30165f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
15 changes: 14 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,20 @@ Linking the package manually is not required anymore with [Autolinking](https://
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
...
</manifest>
</manifest>
```

Android 14+ requires the [`foregroundServiceType`](https://developer.android.com/about/versions/14/changes/fgs-types-required) must be set in your service tag:
```xml
<manifest ... >
...
<application ... >
...
<service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="shortService"/>
...
</application>
...
</manifest>
```


Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ def safeExtGet(prop, fallback) {
}

android {
compileSdkVersion safeExtGet('compileSdkVersion', 31)
compileSdkVersion safeExtGet('compileSdkVersion', 34)

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 31)
targetSdkVersion safeExtGet('targetSdkVersion', 34)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public static Notification buildNotification(@NonNull Context context, @NonNull
notificationIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
}
final PendingIntent contentIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
contentIntent = PendingIntent.getActivity(context,0, notificationIntent, PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_MUTABLE);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
Expand Down

0 comments on commit d30165f

Please sign in to comment.