Android : resuming an app after an opening notification push - java

Here's my problem:
I have an application which includes 3 activities.
-SplashscreenActivity (Launcher - Main)
-LoginActivity
-HomeActivity
--Application killed:--
Normal process:
when I run the application by the dashboard icon, I go through the splash, (i logged in), and coming up on the home.
If I put the application in background and I raise it by the dashboard icon, I go back on the home. Everything is normal.
--Application killed:--
However, for the following process:
I get a push notification. I run the application by this push, I go through the splash, and coming up on the home.
But if I put the application in the background, and I raise it by the dashboard icon, I go through by the splash again systematically. Here is the problem!
Here's my manifest.xml ( EDITED )
<activity
android:name="my.package.SplashscreenActivity"
android:label="#string/app_name"
android:noHistory="false"
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="my.package.LoginActivity"
android:label="#string/app_name"
android:noHistory="false"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:name="my.package.HomeActivity"
android:label="#string/app_name"
android:noHistory="false"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
</activity>
Here's my push notifications BroadcastReceiver (sendNotificationMethod)
private void sendNotification(String message, String title, int count, String type, long threadId)
{
Activity m_activity;
if (App.getInstance().m_currentActivity != null && App.getInstance().isOnPause())
m_activity = App.getInstance().m_currentActivity;
else
m_activity = null;
PendingIntent pendingIntent = null;
Intent intent = null;
if (m_activity != null)
{
intent = new Intent(this, m_activity.getClass());
intent.putExtra("type", type);
intent.setData((Uri.parse("foobar://" + SystemClock.elapsedRealtime())));
pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
}
else
{
PackageManager pm = getPackageManager();
intent = pm.getLaunchIntentForPackage("my.package");
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("type", type);
pendingIntent = PendingIntent.getActivity(App.getInstance(), 0, intent, 0);
}
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.logo_push_lolilol)
.setColor(App.getInstance().getResources().getColor(R.color.colorPrimary))
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message));
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int)threadId, notificationBuilder.build());
}
Do you have "the solution"?
Thank you in advance.

Try this
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

Related

Foreground service not running when App exits

How can I keep the foreground service running even when the user quits the app?
I've tried running the service in another process, but the service still stops after I quit the app.
My AndroidManifest.xml:
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Test"
tools:targetApi="31">
<service
android:name=".Service"
android:enabled="true"
android:process=":service"
android:exported="false" />
<activity
android:process=":activity"
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Service.java:
public class CountdownService extends Service {
NotificationManager notificationManager;
private String createNotificationChannel(String channelId, String channelName) {
NotificationChannel chan = new NotificationChannel(channelId,
channelName, NotificationManager.IMPORTANCE_NONE);
chan.setLightColor(Color.BLUE);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(chan);
return channelId;
}
NotificationCompat.Builder builder;
#NonNull
private Notification getNotification() {
String channelId = createNotificationChannel("id", "name");
builder = new NotificationCompat.Builder(this, channelId);
return builder.setOngoing(true)
.setSmallIcon(R.mipmap.ic_launcher)
.setPriority(PRIORITY_MIN)
.setCategory(Notification.CATEGORY_SERVICE)
.setContentText("Content Text")
.setSubText("Sub Text")
.setContentTitle("Content Title")
.build();
}
#Override
public void onCreate() {
super.onCreate();
startForeground(1, getNotification());
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
And in MainActivity, I start the service like this:
Intent intent = new Intent(this, Service.class);
startForegroundService(intent);
I found that this application has only one process 'service' in the phone settings, but there is no 'activity' process, what is the problem? thanks.
Define what you mean by "exit." If you mean they go into recents and swipe the app away, or go into settings and force quit, no. That's the user saying "I want this app to end". That will kill all services. Something that could run even when the user says it shouldn't is basically malware.

Sending data from notification click to child activity

I have two activities, one called SplashActivity which is the Launcher and the main activity of the app and the second called MainActivity which is the child activity of SplashActivity, based on some event i have a notification created and when notification click i want the MainActivity to open and send data in extra.
My problem is i have tried every solution pops in front of me nothing worked.
this is my current code:
NotificationChannel channel = new NotificationChannel(String.valueOf(12), name, NotificationManager.IMPORTANCE_HIGH);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());
notificationManagerCompat.createNotificationChannel(channel);
// Create an Intent for the activity you want to start
Intent notifyIntent = new Intent(getApplicationContext(), SplashActivity.class);
notifyIntent.putExtra("notify", "notify");
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
// Create the PendingIntent
PendingIntent notifyPendingIntent = PendingIntent.getActivity(
this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT
| PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, String.valueOf(12))
.setSmallIcon(R.drawable.logo)
.setContentTitle(title)
.setContentText(body)
.setVibrate(new long[]{0, 100, 1000, 300})
.setAutoCancel(true)
.setContentIntent(notifyPendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH);
Notification notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// notificationId is a unique int for each notification that you must define
notificationManagerCompat.notify(12, notification);
two activities declaration in manifest:
<activity
android:name=".home.activities.MainActivity"
android:parentActivityName=".SplashActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
any one what is the solution? and why my current code is not working?
please help me i been working two days for this to work.
You forgot putExtra to intent when start MainActivity, you only show log. Try this
Intent i = new Intent(this, destinationActivity);
i.putExtras(getIntent());
Log.e(TAG, "navigateTo: " + getIntent().getStringExtra("notify"));
startActivity(i);
finish();
after a while trying different solutions i didn't know what the problem is.
but what i did is i used this code:
if (getIntent().getExtras() != null)
getIntent().getExtras().keySet().iterator().forEachRemaining(new Consumer<String>() {
#Override
public void accept(String s) {
Log.e(TAG, "accept: " + s);
}
});
to print out the extras keys i have when the activity opens from notification i saw a unique set of keys and i used one of them as trigger for specific action when it opens from notification.

IntentService not starting automatically after phone reboot unless app is started

I'm trying to send a notification at a particular time, this part works perfectly but after I reboot the phone, the service doesn't get started unless the app is opened which then starts the service. I've tried multiple solutions online but still can't fix the issue.
Activity:
private void startNotificationAlarm() {
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, ReminderBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE), intent, 0);
Objects.requireNonNull(alarmManager).setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
BroadcastReceiver:
public class ReminderBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, BootService.class);
intent.setAction("<package>.Receiver");
context.startService(serviceIntent);
} else {
scheduleNotification(context, intent);
}
}
private void scheduleNotification(Context context, Intent intent) {
Notification notification = new NotificationCompat.Builder(context, BaseApp.CHANNEL_ID)
.setSmallIcon(R.drawable.ic_calendar_alert)
.setContentTitle(title)
.setContentText(message)
.setColor(color)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_REMINDER)
.setAutoCancel(true)
.setOnlyAlertOnce(false)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Objects.requireNonNull(notificationManager).notify((int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE), notification);
}
IntentService:
public class BootService extends IntentService {
public BootService() {
super("BootService");
}
#Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
try {
Thread.sleep(5000);
startNotification();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Manifest
<receiver
android:name=".Receiver.ReminderBroadcastReceiver" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<service android:name=".Service.BootService"/>
You have to provide below permission in manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Also you have to make android:exported as true
as per android docs:
android:exported
Whether or not the broadcast receiver can receive messages from sources outside its application — "true" if it can, and
"false" if not. If "false", the only messages the broadcast receiver
can receive are those sent by components of the same application or
applications with the same user ID.
sample code
<receiver android:name=".sample.BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>

Notification using Firebase and Android

I am trying to make an android application where I receive notification using firebase. I followed resources available over the internet.
All I want to do is send notification from firebase, the message that I receive I want to display it in TextView in main activity.
Currently I am testing in an emulator. There are few problems that I am not able to resolve.
I am able to send notification from firebase but:
When the application is running in foreground I don't receive a notification in the android notification panel and nothing happens in the main activity too. That is the text in TextView does not change.
When the application is running in background I do receive the notification in android notification panel with message sent from firebase, clicking the notification main activity opens but the text in TextView does not change.
Firebase Messaging Service
public class VAFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "VAFirebaseMessagingS";
public VAFirebaseMessagingService() {}
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d(TAG, "From: " + remoteMessage.getFrom());
if(remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
sendNotification(remoteMessage.getData().get("text"));
}
if(remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
sendNotification(remoteMessage.getNotification().getBody());
}
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(Intent.EXTRA_TEXT, messageBody);
PendingIntent pendingIntent = PendingIntent
.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setSmallIcon(R.drawable.ic_stat_name);
notificationBuilder.setContentTitle("PFIVA");
notificationBuilder.setContentText(messageBody);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSound(defaultSoundUri);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
Main Activity
public class MainActivity extends AppCompatActivity {
private TextView userFeedbackQuery;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userFeedbackQuery = (TextView) findViewById(R.id.pfiva_user_feedback_query);
final Intent intent = getIntent();
if(intent.hasExtra(Intent.EXTRA_TEXT)) {
String userFeedbackQueryText = intent.getStringExtra(Intent.EXTRA_TEXT);
userFeedbackQuery.setText(userFeedbackQueryText);
}
}
}
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.pfiva.mobile.voiceassistant">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".messaging.FirebaseInstanceService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name=".messaging.VAFirebaseMessagingService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
</manifest>
Please can someone guide what is wrong here? How can i solve the above two problems.
Thanks
After suggestions i made the below changes in Messaging Service, basically added notification channel.
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(Intent.EXTRA_TEXT, messageBody);
PendingIntent pendingIntent = PendingIntent
.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID);
notificationBuilder.setSmallIcon(R.drawable.ic_stat_name);
notificationBuilder.setContentTitle("PFIVA");
notificationBuilder.setContentText(messageBody);
notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSound(defaultSoundUri);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, importance);
notificationManager.createNotificationChannel(channel);
}
notificationManager.notify(0, notificationBuilder.build());
}
Problem i face now is that when the app is running in background, i do receive notification in notification panel and clicking on it open main activity but the text in TextView is not updated.
Two ideas to solve your issue:
Have you register your VAFirebaseMessagingService in your AndroidManifest.xml:
Since Android 8, you must use an Notification Channel to send push notifications. Android

Push notification firebase sometime not received

I have problem that sometimes not received notification. In order to receive notification, I need to restart my application then execute notification.php and notification will appear.But after 30 minute/15 minute when i try again running notification.php , not received any notification (I need to run my app again). I hope you guys can help me solve this problem.Thank you in advance.
notification.php
<?php
require "../../init.php";
include("../../function_lib.php");
$id = $_GET['id'];
$title = "Try App";
$message = "news..";
$path_to_fcm = "https://fcm.googleapis.com/fcm/send"; //send push notification through this firebase url
$server_key = "####";
$topic = "/topics/reminder";
$type = "reminder";
//create http request to firease server
//request need 2 section : 1.header section 2. payload section
//add push notification in payload section
//header section for http request : that content authorization key and content_type of this application
//below are the header section of the http request
$headers = array(
'Authorization:key='.$server_key,
'Content-Type:application/json'
);
/*
$field = array('to'=>$topic,'notification'=>array("title"=>"add title","text"=>"add text","click_action"=>"OPEN_ACTIVITY_1"),
'data'=>array('title'=>$title,'body'=>$message,'type'=>$type,'id'=>$id),'priority'=>"high");
*/
//echo "\n".$key;
// to = refer to fcm token, notification refer to message that wull be use in push notification.
///below are the payload section.
$field = array('to'=>$topic,
'data'=>array('title'=>$title,'body'=>$message,'type'=>$type,'id'=>$id));
//perform json encode
$payload = json_encode($field);
//pass $payload (content json encode) variable to firebase server
//below gonna start url section.gonna use firebase url http to send json to firebase server.
$curl_session = curl_init();
curl_setopt($curl_session,CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session,CURLOPT_POST,true);
curl_setopt($curl_session,CURLOPT_HTTPHEADER,$headers);
curl_setopt($curl_session,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl_session,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
curl_setopt($curl_session,CURLOPT_POSTFIELDS, $payload);
//execute curl
$result = curl_exec($curl_session);
//close curl
curl_close($curl_session);
//close mysqli
//mysql_close($conn);
$path = "../dashboard.php?act=home";
echo ('<script>location.href="'.$path.'"</script>');
?>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mas.khoi.infoevent">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#drawable/icon_logo_only"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<service android:name=".firebase.FcmInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".firebase.FcmMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity android:name=".ScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".fragment.MainActivity">
</activity>
<activity android:name=".EventDetailsActivity">
</activity>
</application>
</manifest>
FcmInstanceIdService.java
public class FcmInstanceIdService extends FirebaseInstanceIdService {
#Override
public void onTokenRefresh() {
//http://stackoverflow.com/questions/38340526/firebase-fcm-token-when-to-send-to-server
String recent_token = FirebaseInstanceId.getInstance().getToken();
//add token to sharepreference
SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(Config.SETTING, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
Log.i("generate token",recent_token);
editor.putString(Config.SETTING_FCM_TOKEN,recent_token);
editor.commit();
}
}
FcmMessagingService.java
public class FcmMessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//if want to use function below need to used change data to notification at $field at server side.
//String message = remoteMessage.getNotification().getBody();
//String title = remoteMessage.getNotification().getTitle();
if(remoteMessage.getData().size()>0){
Log.i("Notification Sucess",""+remoteMessage.getData());
startNotification(remoteMessage);
}else{
Log.i("Notification Failed",""+remoteMessage.getData());
}
}
public void startNotification(RemoteMessage remoteMessage){
String title = remoteMessage.getData().get("title");
String messsge = remoteMessage.getData().get("body");
String type = remoteMessage.getData().get("type");
String id = remoteMessage.getData().get("id");
Log.i("Notification","active");
//Log.i("Notificaition","type:"+type);
//Log.i("Notificaition","id:"+id);
//check if notification eihter is reminder or new quote/event
if (!type.equals("reminder") && id.equals("none")) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(messsge);
notificationBuilder.setSmallIcon(R.drawable.icon_no_bg);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
//super.onMessageReceived(remoteMessage);
}else
if(type.equals("reminder") && ! id.equals("none")) {
Intent intent = new Intent(this, EventDetailsActivity.class);
intent.putExtra("id",id);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(messsge);
notificationBuilder.setSmallIcon(R.drawable.icon_logo_only);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
}
Please check this reference about when onMessageReceived() method is fired.
onMessageReceived() is fired only if app is in foreground for notification messages but for data messages, it will always get handled.

Categories

Resources