0

I am sending push messages to users using firebase, the puh is working fine when the app is running or when its in the background , but when i kill the app using multitask tray, its not receiving the push on some devices ,but on some devices its working flawlessly , Seems the app is receiving the push but not showing it. I searched SO and found similar problems but with no solution to the problem. As my application is heavily dependent on push messages. Is this any way to implement it? I am using following code to restart the service but nothing happens.

  @Override
public void onTaskRemoved(Intent rootIntent) {
    super.onTaskRemoved(rootIntent);

   // Log.d(TAG, "TASK REMOVED");
    PendingIntent service = PendingIntent.getService(
            getApplicationContext(),
            1001,
            new Intent(getApplicationContext(), MyFirebaseMessagingService.class),
            PendingIntent.FLAG_ONE_SHOT);

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 1000, service);
}
megamind11
  • 97
  • 6

2 Answers2

0

Some manufactures have restricted app to start automatically. So if push comes, our app will not receive that broadcast.

We have to enable autostart for our app inorder to work push notification in every case. There may be some settings named "Autostart" . Turn on that for our app.

Sangeet Suresh
  • 2,527
  • 1
  • 18
  • 19
  • Hi, Can i do it programmatically? – megamind11 Feb 17 '17 at 06:01
  • I think you can select some manufacturers who has enabled that feature. Compare manufactures from code and prompt to that activity screen of autostart like given below String manufacturer = "xiaomi"; if(manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) { Intent intent = new Intent(); intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")); startActivity(intent); } – Sangeet Suresh Feb 17 '17 at 06:20
0

Try this way:

{
 "notification" : {
   "body" : "great match!",
   "title" : "Portugal vs. Denmark",
   "icon" : "myicon"
 }
 "data": {
   "message":Hello,
   "member_id":"15",
   "push_type":2
  },
 "re‌​gistration_ids":["er‌​3444@34343sdsadsadsa‌​dsad213213"]
}

When app is not available then firebase is trigger default push from notification object, so you need to use notification object by default and data is use for other data.

Jd Prajapati
  • 1,953
  • 13
  • 24
  • Hi, But if i use the notification tag in the payload ,I can access the data part only when the user taps in the notification. Which is a no go in my situation. – megamind11 Feb 17 '17 at 06:06
  • data part is not working when app is not available, you need to use notification tag. what is the issue with notification tag? can you please explain me? – Jd Prajapati Feb 17 '17 at 06:08
  • i am sending messages which i need to store in the internal database.If the user dismisses the notification, the data will not be received by the app and wont be added to the databse. – megamind11 Feb 17 '17 at 06:10
  • megamind you store in server when you r sending notification and always tack data from server as part of api – android_jain Feb 17 '17 at 06:12
  • you will newer lose data if user not clicked notification – android_jain Feb 17 '17 at 06:12
  • the wierd part is that some devices are recieving the push when killed – megamind11 Feb 17 '17 at 06:15