Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages and notifications at no cost.
Using FCM, you can notify a client app that new email or other data is available to sync. You can send notifications to drive user reengagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.
HOW TO SEND IMAGE IN PUSH NOTIFICATION ?
How does it work?
Firebase Notifications is built on Firebase Cloud Messaging and shares the same FCM SDK for client development. For testing or for sending marketing or engagement messages with powerful built-in targeting and analytics, you can use Notifications. For deployments with more complex messaging requirements, FCM is the right choice.
Implementation path
Set up the FCM SDK | Set up Firebase and FCM on your app according the setup instructions for your platform. |
Develop your client app | Add message handling, topic subscription logic, or other optional features to your client app. During the development, you can easily send test messages from the Notifications console. |
Develop your app server | Decide which server protocol(s) you want to use to interact with FCM, and add logic to authenticate, build send requests, handle response, and so on. Note that if you want to use upstream messaging from your client applications, you must use XMPP. |
Set Up a Firebase Cloud Messaging Client App on Android
To write your Firebase Cloud Messaging Android client app, use the FirebaseMessaging
API and Android Studio 1.4 or higher with Gradle. The instructions in this page assume that you have completed the steps for adding Firebase to your Android project.
FCM clients require devices running Android 4.1 or higher that also have the Google Play Store app installed, or an emulator running Android 4.1 with Google APIs. Note that you are not limited to deploying your Android apps through Google Play Store.
Set up Firebase and the FCM SDK
- If you haven’t already, add Firebase to your Android project.
- In Android Studio, add the FCM dependency to your app-level build.gradle file:
dependencies { implementation 'com.google.firebase:firebase-messaging:17.3.4' }
Edit your app manifest
Add the following to your app’s manifest:
- A service that extends
FirebaseMessagingService
. This is required if you want to do any message handling beyond receiving notifications on apps in the background. To receive notifications in foregrounded apps, to receive data payload, to send upstream messages, and so on, you must extend this service.<service android:name=".MyFirebaseMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>
- (Optional) Within the application component, metadata elements to set a default notification icon and color. Android uses these values whenever incoming messages do not explicitly set icon or color.
<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. See README(https://goo.gl/l4GJaQ) for more. --> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_stat_ic_notification" /> <!-- Set color used with incoming notification messages. This is used when no color is set for the incoming notification message. See README(https://goo.gl/6BKBk7) for more. --> <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/colorAccent" />
- (Optional) From Android 8.0 (API level 26) and higher, notification channels are supported and recommended. FCM provides a default notification channel with basic settings. If you prefer to create and use your own default channel, set
default_notification_channel_id
to the ID of your notification channel object as shown; FCM will use this value whenever incoming messages do not explicitly set a notification channel. To learn more, see Manage notification channels.<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. See README(https://goo.gl/l4GJaQ) for more. --> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_stat_ic_notification" /> <!-- Set color used with incoming notification messages. This is used when no color is set for the incoming notification message. See README(https://goo.gl/6BKBk7) for more. --> <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/colorAccent" />
Check for Google Play Services APK
Apps that rely on the Play Services SDK should always check the device for a compatible Google Play services APK before accessing Google Play services features. It is recommended to do this in two places: in the main activity’s onCreate()
method, and in its onResume()
method. The check in onCreate()
ensures that the app can’t be used without a successful check. The check in onResume()
ensures that if the user returns to the running app through some other means, such as through the back button, the check is still performed. If the device doesn’t have a compatible Google Play services APK, your app can call GooglePlayServicesUtil.getErrorDialog()
to allow users to download the APK from the Google Play Store or enable it in the device’s system settings. For a code example, see Setting up Google Play Services.
Access the device registration token
On initial startup of your app, the FCM SDK generates a registration token for the client app instance. If you want to target single devices or create device groups, you’ll need to access this token by extending FirebaseMessagingService
and overriding onNewToken
.
This section describes how to retrieve the token and how to monitor changes to the token. Because the token could be rotated after initial startup, you are strongly recommended to retrieve the latest updated registration token.
The registration token may change when:
- The app deletes Instance ID
- The app is restored on a new device
- The user uninstalls/reinstall the app
- The user clears app data.
Retrieve the current registration token
When you need to retrieve the current token, call FirebaseInstanceId.getInstance().getInstanceId()
Monitor token generation
the onNewToken callback fires whenever a new token is generated.
/** * Called if InstanceID token is updated. This may occur if the security of * the previous token had been compromised. Note that this is called when the InstanceID token * is initially generated so this is where you would retrieve the token. */ @Override public void onNewToken(String token) { Log.d(TAG, "Refreshed token: " + token); // If you want to send messages to this application instance or // manage this apps subscriptions on the server side, send the // Instance ID token to your app server. sendRegistrationToServer(token); }
After you’ve obtained the token, you can send it to your app server. See the Instance ID API reference for full detail on the API.
Prevent auto initialization
Firebase generates an Instance ID, which FCM uses to generate a registration token and Analytics uses for data collection. When an Instance ID is generated, the library will upload the identifier and configuration data to Firebase. If you prefer to prevent Instance ID autogeneration, disable auto initialization for FCM and Analytics (you must disable both) by adding these metadata values to your AndroidManifest.xml
:
<meta-data android:name="firebase_messaging_auto_init_enabled" android:value="false" /> <meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />
To re-enable FCM, make a runtime call:
FirebaseMessaging.getInstance().setAutoInitEnabled(true);
This value persists across app restarts once set.
Once the client app is set up, you are ready to start sending downstream messages with the Notifications composer.
Send a message from the Notifications console
- Install and run the app on the target devices.
- Open the Notifications tab of the Firebase console and select New Message.
- Enter message text.
- Select the message target. The dialog displays further options to refine the target based on whether you chooseApp/App Version, Device Language, or Users in Audience.
After you click Send Message, targeted client devices that have the app in the background receive the notification in the system notifications tray. When a user taps on the notification, the app launcher opens your app.
Receive and handle notifications
If you want to receive notifications when your app is in the foreground, you need to add some message handling logic in your client app.
To receive messages, use a service that extends FirebaseMessagingService. Your service should override the onMessageReceived
callback, which is provided for most message types, with the following exceptions:
- Notifications delivered when your app is in the background. In this case, the notification is delivered to the device’s system tray. A user tap on a notification opens the app launcher by default.
- Messages with both notification and data payload. In this case, the notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
If you want to open your app and perform a specific action other than the default action, set click_action
as described below.
In summary:
App state | Notification | Data | Both |
---|---|---|---|
Foreground | onMessageReceived |
onMessageReceived |
onMessageReceived |
Background | System tray | onMessageReceived |
Notification: system tray Data: in extras of the intent. |
For more information about message types, see Notifications and data messages.
Edit the app manifest
To use FirebaseMessagingService
, you need to add the following in your app manifest:
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
Override onMessageReceived
By overriding the method FirebaseMessagingService.onMessageReceived
, you can perform actions based on the received message and get the message data:
@Override public void onMessageReceived(RemoteMessage remoteMessage) { // ... // TODO(developer): Handle FCM messages here. // Not getting messages here? See why this may be: https://goo.gl/39bRNJ Log.d(TAG, "From: " + remoteMessage.getFrom()); // Check if message contains a data payload. if (remoteMessage.getData().size() > 0) { Log.d(TAG, "Message data payload: " + remoteMessage.getData()); if (/* Check if data needs to be processed by long running job */ true) { // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher. scheduleJob(); } else { // Handle message within 10 seconds handleNow(); } } // Check if message contains a notification payload. if (remoteMessage.getNotification() != null) { Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); } // Also if you intend on generating your own notifications as a result of a received FCM // message, here is where that should be initiated. See sendNotification method below. }
Handle messages in a backgrounded app
When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.
This includes messages that contain both notification and data payload. In these cases, the notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
If you want to open your app and perform a specific action, set click_action
in the notification payload and map it to an intent filter in the Activity you want to launch. For example, set click_action
to OPEN_ACTIVITY_1
to trigger an intent filter like the following:
<intent-filter>
<action android:name="OPEN_ACTIVITY_1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Background Restricted Apps (Android P or newer)
Starting Jan 2019, FCM will not deliver messages to apps which were put into background restriction by the user (such as via: Setting -> Apps and Notification -> [appname] -> Battery). Once your app is removed from background restriction, new messages to the app will be delivered as before. In order to prevent lost messages and other background restriction impacts, make sure to avoid bad behaviors listed by the Android vitals effort. These behaviors could lead to the Android device recommending to the user that your app be background restricted. Your app can check if it is background restricted using: isBackgroundRestricted().
Many of these options are available only through the Firebase Cloud Messaging server implementation. For the full list of message options, see the reference information for your chosen connection server protocol, HTTP or XMPP.
How to find Firebase Api key ?
1- Go to Firebase Console.
2- Select your project.
3- Then go to Project Setting.
4- Click Cloud Messaging tab and Copy Server Key.
Error:(15, 5) error: method does not override or implement a method from a supertype
Post your error code
Sir i want send notification for single device what can i do ……
sending notification through the fcm id,U Uid(User id), Instance Id(Instanlling app one id created)
fcm id
thank you
Hi.. sir whenever sending notification through the app server some it will come or does’t come or should be late ……. if u have any problem mycode or app server
maybe that’s internet problem
In the project android studio in the class java: Register activity is the string:
public static String BASE_URL = "http://192.168.1.100/fcm_server/register.php";
Why it is not the php file in the server?
thank
https://github.com/akrajilwar/Firebase-Cloud-Messaging/tree/master/server_side_code
Hi, how to send notifications from website to Android apps ? Is it possible ?
Yes, It is possible. You can make an admin panel for sending notification.
Thanks boss, did you any tutorial for that, or can you do one for us please ?
This is my Android Push Notification post. you can make an admin panel from here.
What is “fcm_id:” ? at “register.php” ?
fcm_id is a Firebase Registration Id. Firebase Registration Id is automatically generate when you integrate firebase in your android project. more info about fcm id.
The notification is not showing when the app is in the background, trying to look for the solution, but they are all for expert (just explaining without showing how to do it). Can you please help me? Thank you!
use my source code. it’s working if app running in background.
Hey there the
FirebaseInstanceId.getInstance().getToken()
always return null on first attemptconnect your phone to the internet
How to send same notification to number of device. I used “to” as array in “fields” array. In gcm it was working fine. But in fcm it is not getting notification
use ‘registration_ids’ for multiple devices
Error:(17, 0) SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
Go to your project setting and check Android SDK Location
“Go to File->Project Structure->Android SDK Location”
Nice tutorial..thank you.:-)
How to set notification sound when the app is in background??
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
use
.setSound(defaultSoundUri)
inNotificationCompat.Builder
method inMyFirebaseMessagingService.java
file{“to”:null,”priority”:”high”,”notification”:{“tag”:”chat”,”body”:”yehaaa”}} ….null on “to”
The Value of to must be a registration token
Thanks for fast reply, can’t reply on your ori comment..basicly, “fcm_registered_id” is referred to what? Project ID? App ID or Sender ID?… {“multicast_id”:7865128904096947312,”success”:0,”failure”:1,”canonical_ids”:0,”results”:[{“error”:”InvalidRegistration”}]}
i already got the FCM_registered_id…thanks for great tutorial
String fcm_id = FirebaseInstanceId.getInstance().getToken();
this fcm ID is unique to one device or unique to one package (com.myproject.fcm)?..if unique to one device, how to send to all installed device with same package…do you have any tutorial on that..sorry for many questions, i’m very novice in android dev
use ‘registration_ids’ for multiple devices
Akshay, would this php code support “registration_ids”? because in registration.php ask only for fcm_id
registration_ids is a fcm_id
Hi Thanks, this code is working on my device. But I got some bugs, when I push FCM to my app (on background) the small icon will show white (this use launcher from manifest). But when I open the app, the icon is correct using my drawable. Can you help me?
I didn’t understand. Can you send me screen shot to my email or facebook?
Hello Akshay !
Thanks for Great Tutorial on PushNotifications !
but two bugs detected..
1. when the app is in backgroung image is not coming, only text is showing..(even i send image push)
2. when the app is running state image is coming (good)..but when i send only text push without image..text is not coming but showing blank_space in the place of image..
here is my backend :
http://droid.oxywebs.in/fcm/admin.php
here is the app link :
http://droid.oxywebs.in/ga/app-release.apk
i executed the exact code !!
can you please check it out ??
ok… i’m checking…
k ! Thank you..
iam waiting..
i updated source code and Firebase have a bug in Big Image Style if app is in the background
ok! Thank you ..
may i know what changes you made now???
i will let u know what happend after building with updated code (may be on Tommarow)
once again , Thanks for such Great Tutorial 🙂
Hello Akshay Raj
Please Inform Me What to do in server side files please Help me i m newbie in android .
Which one is Edit in serverside files to run this project
I updated all files. You can build with all source code.
When app in background, is there any way that i can catch the push notification and modify notificaiton settings ( for example : add image, change notification style, sound). I remember GCM allow you to do that.
I also working on it because fcm showing only message if app in the background.
I have an Error in
MyApplication.getInstance().addToRequestQueue(strReq, tag_string_req);
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException nikunj.paradva.testpush.RegisterActivity.registerToServer(RegisterActivity.java:135)
at nikunj.paradva.testpush.RegisterActivity.access$200(RegisterActivity.java:28)
at nikunj.paradva.testpush.RegisterActivity$1.onClick(RegisterActivity.java:56)
Finally One issue remaining
When My App was running and I am sending notification throw FCM Consol then App was Crashed
LOG:—>>>>
pool-5-thread-1
java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equalsIgnoreCase(java.lang.String)’ on a null object reference
at nikunj.paradva.testpush.MyFirebaseMessagingService.sendNotification(MyFirebaseMessagingService.java:75)
at nikunj.paradva.testpush.MyFirebaseMessagingService.onMessageReceived(MyFirebaseMessagingService.java:58)
Check line 75 in MyFirebaseMessagingService.java
Hi Akshay,
Getting these error when app receives notification,
E/GcmReceiver: Failed to resolve target intent service, skipping classname enforcement
E/GcmReceiver: Error while delivering the message: ServiceIntent not found.
Please help me to resolve the issue.
Thanks
Are you using GCM?
No
Add fcm services to AndroidManifest.xml file
services are also in place..
Check my source code…maybe you find your solution
I want to start a new activity when user taps the notification. How to do it?
add
"click_action" => "OPEN_ACTIVITY_1"
in notification array in admin.php and add below lines to your new activity in Android Manifest fileHello,I am sending notifications to the android devices using FCM, Now I want to send the notification to android & Ios at a same time & to the intended devices only, can you help me on that??
use same method like android
Hey Akshay can you elaborate this
check this link Setting Up a Firebase Cloud Messaging Client App on iOS
how to create beep sound when the notification is arrived to our mobile phone..? do you have the coding & where to put it..? on Php file or in MyFirebaseMessagingService.java..
check this line
.setSound(defaultSoundUri)
inMyFirebaseMessagingService.java
file.if you want to use custom sound then put below code
Uri notification = Uri.parse("android.resource://com.circleeduventures.app/raw/message");
.setSound(notification )
and put your sound file (message.mp3) to
"res/raw/"
Where to put Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
It is inside private void showNotification(Stringe message) method..?
yes
Tq very much Akshay Rai…I using default ringtone..Works..!! later I will try custom sound…btw where is “res/raw/”..? thanks in advance
your projects folder :
YourProject\app\src\main\res\raw
Raj , from some reason the defalt ringtone is not working for me , this is my code, what i am doing worng , i try also to use a ringtone from my resource and it’s doesnt work for me also.
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_ONE_SHOT);
Uri sound= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
//Uri sound = Uri.parse(“android.resource://” + getPackageName() + “/” + R.raw.chat_ringtone_pop);
mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.check_me_logo)
.setContentTitle(mTitle)
.setContentText(message)
.setAutoCancel(true)
.setSound(sound)
.setContentIntent(pendingIntent);
mNotificationId = (mNotificationId == MAX_NOTIFICATIONS) ? 1 : mNotificationId + 1;
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, mNotificationId, i, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
mNotifyMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotifyMgr.notify(0, mBuilder.build());
thanks!
Clean your project
(Build->Clean Project)
then runHi Akshay Raj,
Do you have any code that once I received notification to my System tray (mobile phone), how to pass these message to my Activity (New Screen Layout) so that I can see more clear the notification text is all about.
you can use
Bundle
for parsing data to activity. more informationHi Raj
I already manage to send notification message from php file and send to mobile phone using fcm. Once the user click on the notification message on mobile tray, it will redirect to other layout with same message plus time and date…is it possible to do that…?
It’s all set. I have exactly the same code as you have provided. But only question is..
How to set notification sound when the app is in background?
However notification sound appears while app is running foreground.
p.s. it would be great if you provide tips for vibration too.
Thank you so much
Hi Akshay,
I need to send notification from my app to same app installed in different device using FCM. It is possible like this? Please provide an example for this
send msg to target device’s registration id
Hello Akshay, I have stuck in issue that everyone gives tutorial of pushnotification but he is not given any detail code after that issues. my issues is that i want to go under 4th activity when i click notification with some value which is need of my 4th Activity.. i did not , how to use getintent().getExtra() and any other solution. when my app in background i click the notification but it comes from splash screen.. please help me..
add
"click_action" => "OPEN_ACTIVITY_1"
in notification array in admin.php and add below lines to your new activity in Android Manifest fileand send your data by Bundle method or check here
its working fine from firebase console but in whenever i am trying send image aur message from server side,its showing unauthorized error401,even i put my API
Check with my source code
http://stackoverflow.com/questions/40128881/onmessagereceived-method-not-called-when-app-in-background-in-fcm-pushnotificati
Please See this.. I am not get solution yet.
I have answered your question.
{“registration_ids”:[“eQiC16pW2Ds:APA91bGus8mGu2hekqaavdvX7qS3X-joEdj8frZ_IoX4uYeFNNRe4ML8D7wm9nJX5trIFqPHarMsk__YemzljwXxa56IfG-gmEnj96QHs2B1V66IrNosP8vJVZdBOk1Cw6PE2bVq3pGH”],”notification”:{“title”:”Compunet Connections”,”body”:”test”,”image_url”:”http:\/\/www.employabilitybridge.com\/wp-content\/uploads\/2016\/05\/compunet.png”,”type”:”1″}}{“multicast_id”:8319232331329377663,”success”:1,”failure”:0,”canonical_ids”:0,”results”:[{“message_id”:”0:1476942665420987%55e5333a55e5333a”}]}
Am i sending the image url correctly because the message is only displaying in the notification
Open your app then check notification
And my another question is how can i achieve dynamic linking through notification
Use intent.putExtra() or Bundle method
ok, my only problem is sending the image in notification,
Though im sending the image url through php whether it will work when app is in back ground or i should keep the app running
Image not showing in notification if app in the background maybe this is a bug in girebase and you can use bundle to send your image to activity. If i find any solution of this problem i will post here.
ok thanks…
🙂
Without Android studio can i send a Message notification in firebase cloud messaging
Yes… You can send a message between device to device and web to device and device to web.
how is it possible bro?
Read this tutorial Android Push Notifications using Firebase
Error:Failed to complete Gradle execution.
Cause:
Process ‘command ‘/opt/android-studio/jre/bin/java” finished with non-zero exit value 126
how to rectify this error ????????
check with clean your project or reinstall android studio
E/RegisterActivity: Register Error: null
D/Volley: [1] Request.finish: 7612 ms: [ ] http://192.168.42.174/fcm_server/register.php 0x371b3c5d NORMAL 3
NetworkDispatcher.run: Unhandled exception java.lang.NullPointerException: Attempt to invoke virtual method ‘int java.lang.String.length()’ on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method ‘int java.lang.String.length()’ on a null object reference
check your internet connection and test again.
how to send push notification web to web ?
could you please help me
check this Set Up a JavaScript Firebase Cloud Messaging Client App
We developed a web projects so any what ever registered users in that project we can send push notifications , this is not a android app could you please help me.
Hi Akshay,
we develop web project using php we need to send the push up notifications , so please help me on that like web to web push notifications
check this Set Up a JavaScript Firebase Cloud Messaging Client App
Error:create process error=216,this version of %1 is not compatible with the version of windows you’re running, How to rectify this error??????????? and i am using a windows 8 Os
you are using a different type (32-bit or 64-bit) software. check your system type in system properties then reinstall correct software. (Shortcut key for System Properties: Win + Pause Break)
InvalidRegistration
earlier it waz working fine but now unfortunately its showing this error whenever am trying to push notification from admin panel,even i used token to send as single user push from firebase console but its not working from admin panel
check with new registration
bro i did everything even i replace whole code even though its not working,nd new error whenever am tryng to get token in any other acivity such as in my app register activity its crashing ma app!!plz help am frusted now,i wasted 3 days in this even though its working!!
Send your source code to my email so i can check this. My email is [email protected]
i sent u php file,should i send u my DB file which is stored on local host
Send your android studio project files.
those files are same as u have iam just copying Token from log and paste in my DB,and then accesing same token from admin panel,even though i will send ma project.
Hi Akshay,
i gone through the document but could you plz provide the sample on this
String Token = FirebaseInstanceId.getInstance().getToken();
is not fetching firebseId in fregment but its fetching activity,
1)how can i fetch id in frament???
2)how can i migrate into fragment from notification rather than activity???
Hi. thanks for the tutorial. Can you help me send notifications from mysql database (where images are added) to android app when new rows are added to my table?
add below code to your admin panel for saving data to mysql table.
same here
Hi,
Can you please help me in developing app server by using xmpp, I wanted to use xmpp in my app server bu I am not getting any clue, I have gone through XMPPHP, JAXL libraries but not getting how to do it.
please help me.
Hello Akhsay, I want to send notification from one device to another using fcm .i saw many tutorial but it always show me tutorial in which we send notification from fcm console .
Check this https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html?m=1
Hi Akshay,
i’m new to android.
i’m getting error like ” java.lang.NullPointerException” in Register Activity.
can u please help me
connect your device with internet connection because your fcm id didn’t generate.
Hi Akshay,
I’m waiting for your reply.
i have connected,but i’m getting same error sir
Uninstall your application then install again and check application log for registration values.
Process:
java.lang.NullPointerException
at yash.fcmproject1.RegisterActivity.registerToServer(RegisterActivity.java:134)
at yash.fcmproject1.RegisterActivity.access$200(RegisterActivity.java:28)
at yash.fcmproject1.RegisterActivity$1.onClick(RegisterActivity.java:56)
i’m getting these error , can anyone help me please
send your source code to my email ([email protected])
In your AndroidManifest.xml add
i’ve forwarded my code please check it and tell me
push notifications comes but image not receiving in android phone
use my source code
This works only if apk is installed directly from Android studio. When I send the app to another phone this doesn’t work, please help.
Sign your apk then install to another device
hi akshay. I am able to send notifications only to emulator but not to real mobile devices.. Can u plz help with that
clean your project and try again.
this code is not working with ios can you please guide
The Php code is not working for ios
This tutorial is based on Android. So please visit below link for iOS.
Firebase Cloud Messaging for iOS
Hi. If I wanted the server to send push notifications automatically when a new row gets added in the databse, what changes do I make? Please help me out.
add send notification method to your insert row function.
nice Tutorial Sir! code works fine but when clicking on notification , it show nothing on app screen activity.
you need to parse date with intent. check this for parse data in activities
Passing Data Between Activities
got it sir Thnx!
Hello Akshay! I want to have token for each login user separately(on same device or not), how can I do this? I want to save token for each login user in database and refer that token to send FCM message. Thanks
this tutorial has for separate login user and also save their device’s id (token) to MySQL database. test with different email ids and if you getting any problem then comment here. I’ll help you.
Sir, Can I run this application on the real android device? How I will be able to send token to wamp server through real android device. Kindly help
Thanks and Best Regards.
yes, you can run in real android device. only change your IP address in
RegisterActivity.java
for connecting your device to wamp server.I am using this same code getting error database problem on registering time
HomeActivity is missing
this is
MainActivity
. Sorry for missprint.Check your IP address or MySQL connection. maybe your password of MySQL connection is wrong.
please tell me
1. Fcm id –> is generated by individual device then store into server
2. Notification is communicate whether Fcm ID or UId
HI Akshay g,
how many device will support fcm is it free of cost?
is there any way to send push notifications directly from server to client with out any third party(Like fcm)
thanks in advance
fcm is free for lifetime and unlimited devices.
I want to handle foreground and background notification
I received below error after 1 min of closing app.
and no notification received by device.
E/FirebaseInstanceId: Error while delivering the message: ServiceIntent not found.
Can you show me your integration on facebook or whatsapp?
Hi sir, it not work in Oreo(both forground, background) and not in forground for other. It only work in background for other device except Oreo. Give me any feasible solution. Sorry for my English , thanks in advance.
add this to sendNotification()
{“status”:”fail”,”message”:”could not move file”}{“status”:”success”,”message”:”http:\/\/bilsakcompany.com\/uploads\/1585583145632.jpg”}
{“multicast_id”:3032715822910905022,”success”:0,”failure”:1,”canonical_ids”:0,”results”:[{“error”:”InvalidRegistration”}]}
Nice Project.
How can i send to multiple user at same time.
How can i also send the notification from my android device but not from web.
you need firebase admin for send notification