My App Crash every time I send a One Signal Push notification. note: firebase has no issue also one signal inApp message working fine. also, Receive push notification of one signal with the crash
with firebase, it has no issue but I want to use one signal I tries so many things but not working
Here is my error from logcat
The Error
<pre lang="Java">2021-07-20 22:10:37.431 14322-16493/###### E/AndroidRuntime: FATAL EXCEPTION: Firebase-Messaging-Intent-Handle
Process: #######, PID: 14322
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.messaging.RemoteMessage$Notification.getTitle()' on a null object reference
at ######.MyFirebaseMessagingService.onMessageReceived(MyFirebaseMessagingService.java:17)
at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging@@22.0.0:13)
at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging@@22.0.0:8)
at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging@@22.0.0:3)
at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging@@22.0.0:3)
at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(com.google.firebase:firebase-messaging@@22.0.0:1)
at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(Unknown Source:6)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.5.0:6)
at java.lang.Thread.run(Thread.java:764)
Here are my codes
I have added both the firebase class and one signal class in the manifest file
Android Manifest
<pre>="1.0"="utf-8"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="######"
android:installLocation="auto">
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true" />
<application
android:name=".AppController"
android:allowBackup="false"
>
<activity android:name=".activity.MainActivity" />
<activity
android:name=".activity.SplashScreen"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<activity
android:name=".activity.SettingActivity"
android:label=""
android:theme="@style/Theme.AppCompat.Light.Dialog" />
<activity
android:name=".activity.InstructionActivity"
android:label="My Custom AppIntro"
android:theme="@style/Theme.Intro" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="@string/admob_app_id" />
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />
<meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_yellow" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
<meta-data android:name="com.onesignal.NotificationAccentColor.DEFAULT"
android:value="#FFCC00" />
<activity android:name=".activity.ReviewActivity" />
<activity android:name=".activity.BookmarkList" />
<activity android:name=".AboutUs" />
<activity android:name=".About" />
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
Build. Gradle (app)
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "#########"
minSdkVersion 17
targetSdkVersion 30
versionCode 1
versionName "1.0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
archivesBaseName = "Offline Quiz"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.firebase:firebase-messaging:22.0.0'
implementation 'com.google.firebase:firebase-analytics:19.0.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
implementation 'com.google.firebase:firebase-inappmessaging-display:20.0.0'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.android.gms:play-services-ads:19.4.0'
implementation 'com.google.android.gms:play-services-plus:17.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'org.jsoup:jsoup:1.11.3'
implementation 'com.google.android.gms:play-services-games:21.0.0'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
implementation 'com.google.android.gms:play-services-location:18.0.0'
implementation 'com.github.AppIntro:AppIntro:6.1.0'
implementation 'io.github.dreierf:material-intro-screen:0.0.6'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.onesignal:OneSignal:4.4.1'
implementation platform('com.google.firebase:firebase-bom:28.2.1')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging'
}
apply plugin: 'com.google.gms.google-services'
Build.Gradle(project)
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.google.gms:google-services:4.3.8'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.13.4'
}
}
allprojects {
repositories {
mavenCentral()
jcenter()
maven {
url "https://maven.google.com"
}
google()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Firebase class
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import org.jetbrains.annotations.NotNull;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived( RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
getFirebaseMessage(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
}
public void getFirebaseMessage (String title, String msg)
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,"myFirebasechannel")
.setSmallIcon(R.drawable.ic_notification_test)
.setContentTitle(title)
.setContentText(msg)
.setAutoCancel(true);
NotificationManagerCompat manger=NotificationManagerCompat.from(this);
manger.notify(101,builder.build());
}
}
please Help
What I have tried:
Tried to change @nullable but not working