Reputation: 205
I tried to test my app with sending the notification via console in firebase cloud messaging, But when my app in the foreground or still running. The notification do not show in the device and the log in the firebase messaging service is triggered.
But when i destroy my app, the notification work nicely.
This is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.yehezkiel.eclassapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/eclass_logo1"
android:label="@string/app_name"
android:roundIcon="@mipmap/eclass_logo1"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:icon">
<service
android:name=".myFirebaseInstanceTokenID">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<activity
android:name=".LoginActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity android:name=".Tugas" />
<activity
android:name=".DetailActivity"
android:label="@string/title_activity_detail"
android:theme="@style/AppTheme" />
<activity android:name=".NilaiActivity" />
<activity android:name=".BaseActivity" />
<activity android:name=".MateriActivity" />
<activity android:name=".NilaiDetailActivity" />
<activity android:name=".PesertaActivity"></activity>
</application>
</manifest>
This my firebasemessagingservice
public class myFirebaseInstanceTokenID extends FirebaseMessagingService {
private static final String TAG = "FirebaseMessagingServce";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getData().size() > 0) {
Log.e(TAG, "Message data payload: " + remoteMessage.getData());
}
Log.e(TAG, "Tidak ada Data");
}
}
Upvotes: 2
Views: 8746
Reputation: 3192
The default implementation will not show a notification when your application is in the foreground. You will need to handle onMessageReceived(...)
yourself and create and display a notification as needed.
From the documentation:
Firebase notifications behave differently depending on the foreground/background state of the receiving app. If you want foregrounded apps to receive notification messages or data messages, you’ll need to write code to handle the onMessageReceived callback. For an explanation of the difference between notification and data messages, see Message types.
Upvotes: 0
Reputation: 317322
What you're observing is is how notification type messages work on Android. When your app is in the foreground, you will not see a notification in the tray.
Please read the documentation on handling messages to understand what to expect. Especially see the "in summary" box that tells you how message handling is different between foreground and background states of your app. Not that when your app is in the foreground, you can only expect that your message will be seen in onMessageReceived
. You can construct a notification there yourself, if needed.
Upvotes: 7