diff --git a/example/android/build.gradle b/example/android/build.gradle index bbc90625a..edaa8977a 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,19 +1,19 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext{ - androidSdkVersion = 31 + ext { + androidSdkVersion = 30 androidMinSdkVersion = 21 kotlinVersion = "1.3.61" kotlinStdlib = "kotlin-stdlib-jdk8" detoxKotlinVersion = kotlinVersion - } + } repositories { google() mavenCentral() } dependencies { - classpath "com.android.tools.build:gradle:4.0.2" + classpath "com.android.tools.build:gradle:4.2.2" classpath "com.google.gms:google-services:4.3.3" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } @@ -21,14 +21,14 @@ buildscript { allprojects { repositories { - mavenLocal() - mavenCentral() - google() - maven { - // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm - url "$rootDir/../../node_modules/react-native/android" - } + maven { url "$rootDir/../../node_modules/react-native/android" } maven { url "$rootDir/../../node_modules/jsc-android/dist" } + mavenCentral { + content { + excludeGroup "com.facebook.react" + } + } + google() maven { url 'https://www.jitpack.io' } } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 9e50ffd4f..966aa8e62 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Thu Dec 12 22:59:18 IST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip diff --git a/example/android/myapplication/build.gradle b/example/android/myapplication/build.gradle index e71430a36..d20c48f28 100644 --- a/example/android/myapplication/build.gradle +++ b/example/android/myapplication/build.gradle @@ -12,7 +12,7 @@ project.ext.react = [ bundleInBeta : true, hermesFlagsDebug:['-Xes6-proxy','-output-source-map'], hermesFlagsRelease:['-output-source-map'], - hermesCommand: "../../../node_modules/react-native/node_modules/hermes-engine/%OS-BIN%/hermesc", + hermesCommand: "../../../node_modules/hermes-engine/%OS-BIN%/hermesc", ] apply from: "../../../node_modules/react-native/react.gradle" @@ -51,7 +51,7 @@ dependencies { //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" - def hermesPath = "../../../node_modules/react-native/node_modules/hermes-engine/android/"; + def hermesPath = "../../../node_modules/hermes-engine/android/"; debugImplementation files(hermesPath + "hermes-debug.aar") releaseImplementation files(hermesPath + "hermes-release.aar") implementation "org.jetbrains.kotlin:$kotlinStdlib:$kotlinVersion" diff --git a/example/android/settings.gradle b/example/android/settings.gradle index ac64752eb..e5b7932bd 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,3 +1,4 @@ +rootProject.name = 'NotificationsExampleApp' include ':myapplication' include ':react-native-notifications' diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java index 9f568b8f2..eadf41ec3 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.app.Application; +import android.content.Context; import android.content.Intent; import android.os.Bundle; @@ -94,9 +95,10 @@ public void onActivityDestroyed(Activity activity) { private void callOnOpenedIfNeed(Activity activity) { Intent intent = activity.getIntent(); if (NotificationIntentAdapter.canHandleIntent(intent)) { - Bundle notificationData = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R ? + Context appContext = mApplication.getApplicationContext(); + Bundle notificationData = NotificationIntentAdapter.cannotHandleTrampolineActivity(appContext) ? NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent) : intent.getExtras(); - final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData); + final IPushNotification pushNotification = PushNotification.get(appContext, notificationData); if (pushNotification != null) { pushNotification.onOpened(); } diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java index 5f5607844..41b48242a 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java @@ -14,12 +14,12 @@ public class NotificationIntentAdapter { @SuppressLint("UnspecifiedImmutableFlag") public static PendingIntent createPendingNotificationIntent(Context appContext, PushNotificationProps notification) { - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { + if (cannotHandleTrampolineActivity(appContext)) { Intent mainActivityIntent = appContext.getPackageManager().getLaunchIntentForPackage(appContext.getPackageName()); mainActivityIntent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle()); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(appContext); taskStackBuilder.addNextIntentWithParentStack(mainActivityIntent); - return taskStackBuilder.getPendingIntent((int) System.currentTimeMillis(), PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); + return taskStackBuilder.getPendingIntent((int) System.currentTimeMillis(), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); } else { Intent intent = new Intent(appContext, ProxyService.class); intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle()); @@ -27,6 +27,10 @@ public static PendingIntent createPendingNotificationIntent(Context appContext, } } + public static boolean cannotHandleTrampolineActivity(Context appContext) { + return android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R && appContext.getApplicationInfo().targetSdkVersion >= 31; + } + public static Bundle extractPendingNotificationDataFromIntent(Intent intent) { return intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME); } diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java index dedc98ad6..b93f762a4 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java @@ -213,7 +213,7 @@ private void notifyOpenedToJS() { } protected void launchOrResumeApp() { - if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.R) { + if (!NotificationIntentAdapter.cannotHandleTrampolineActivity(mContext)) { final Intent intent = mAppLaunchHelper.getLaunchIntent(mContext); mContext.startActivity(intent); } diff --git a/package.json b/package.json index 805a1d666..313655cc0 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@types/jest": "24.9.0", "@types/lodash": "4.14.170", "@types/react": "16.9.35", - "@types/react-native": "0.66.12", + "@types/react-native": "0.67.1", "@types/react-test-renderer": "16.9.2", "babel-eslint": "10.0.3", "detox": "^19.4.2", @@ -64,7 +64,7 @@ "metro-react-native-babel-preset": "0.66.2", "react": "17.0.2", "react-autobind": "1.0.6", - "react-native": "0.66.3", + "react-native": "0.67.3", "shell-utils": "1.0.10", "ts-mockito": "2.5.0", "tslint": "6.1.2", @@ -131,4 +131,4 @@ "html" ] } -} \ No newline at end of file +}