Using Android, when I received a notification push throw my GCMIntentService, I want to know if my app is open or not, because if my app is open when the user click on the notification I want to do nothing, but if the app is close I want to open the app.
App publishers can send them at any time, since users don't have to be in the app or using their devices to receive them. Push notifications look like SMS text messages and mobile alerts, but they only reach users who have installed your app.
Sending a test Android push notificationClick on Settings and open Mobile Apps. Click on the Android App and make sure the Firebase API key has been configured. Click on Test Push and enter the device token for your test device. Add a test payload and send the test.
Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.
Launch the root activity (the one that has ACTION=MAIN and CATEGORY=LAUNCHER in the manifest) and add Intent.FLAG_ACTIVITY_NEW_TASK
. If the app is already active (no matter which activity is on top) this will just bring the task to the front. If the app isn't active, it will start it with your root activity.
Define this in all the activities : 1.) Define a static final boolean flag named 'check_running mode' 2.) Define(override) onResume() and onPause() methods in all activities. 3.) Set the value of this falg as 'true' in onResume() and 'false' in OnPause() methods respectively. 4.) Check out when u receive the push notification : a. If falg value is true it means app is in forground so do nothing in that case b. If flag value is false it means app is in background so You can open the app in that case
NOTE: The falg must be static final as you can change it from any of the activity and access it in your receiver class simply. I hope it'll work for you!
1 :
static boolean check_running mode = false;
-------------------
2:
@Override
protected void onResume() {
super.onResume();
check_running mode = true;
}
@Override
protected void onPause() {
check_running mode = false;
super.onPause();
}
---------------------
3 :
if (check_running mode) {
showUserView();
}
else {
showNotification();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With