Sending Push Notification By PHP
Creating MySQL Database
1. Open phpmyadmin panel by going to http://localhost/phpmyadmin and create a database called fcm. (if your localhost is running on port number add port number to url)
2. After creating the database, select the database and execute following query in SQL tab to create users table.
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fcm_registered_id` text,
`name` varchar(50) NOT NULL,
`email` varchar(255) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Check the following video to know about creating database and php project.
Creating & Running the PHP Project
When we are making request to FCM server using PHP i used curl to make post request. Before creating php project enable curl module in your php extensions.
Left Click on the WAMP icon the system try -> PHP -> PHP Extensions -> Enable php_curl
1. Goto your WAMP folder and inside www folder create a folder called fcm_server. (In my case i installed wamp in D:\WAMP)
2. Create a file called config.php
<?php
$username = "root";
$password = "root";
$host = "localhost";
$dbname = "fcm";
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
try
{
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
}
catch(PDOException $ex)
{
die("Failed to connect to the database: " . $ex->getMessage());
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
{
function undo_magic_quotes_gpc(&$array)
{
foreach($array as &$value)
{
if(is_array($value))
{
undo_magic_quotes_gpc($value);
}
else
{
$value = stripslashes($value);
}
}
}
undo_magic_quotes_gpc($_POST);
undo_magic_quotes_gpc($_GET);
undo_magic_quotes_gpc($_COOKIE);
}
header('Content-Type: text/html; charset=utf-8');
session_start();
?>
3. Now create registration file register.php
<?php
require("config.inc.php");
if (!empty($_POST)) {
$response = array("error" => FALSE);
$query = " SELECT * FROM users WHERE email = :email";
//now lets update what :user should be
$query_params = array(
':email' => $_POST['email']
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["error"] = TRUE;
$response["error_msg"] = "Database Error1. Please Try Again!";
die(json_encode($response));
}
$row = $stmt->fetch();
if ($row) {
$response["error"] = TRUE;
$response["error_msg"] = "I'm sorry, this email is already in use";
die(json_encode($response));
} else {
$query = "INSERT INTO users ( name, email, fcm_registered_id, created_at ) VALUES ( :name, :email, :fcm_id, NOW() ) ";
$query_params = array(
':name' => $_POST['name'],
':email' => $_POST['email'],
':fcm_id' => $_POST['fcm_id']
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["error"] = TRUE;
$response["error_msg"] = "Database Error2. Please Try Again!";
die(json_encode($response));
}
$response["error"] = FALSE;
$response["error_msg"] = "Register successful!";
echo json_encode($response);
}
} else {
?>
<h1>Register</h1>
<form action="register.php" method="post">
name:<br />
<input type="text" name="name" value="" />
<br /><br />
email:<br />
<input type="text" name="email" value="" />
<br /><br />
fcm_id:<br />
<input type="text" name="fcm_id" value="" />
<br /><br />
<input type="submit" value="Register" />
</form>
<?php
}
?>
4. Create another file called admin.php
<?php
require("config.inc.php");
$query = "SELECT * FROM users";
$stmt = $db->query($query);
$target_path = 'uploads/';
if (!empty($_POST)) {
$response = array("error" => FALSE);
function send_gcm_notify($reg_id, $message, $img_url, $tag) {
define("GOOGLE_API_KEY", "AIzaSyBsGSPuDKtN5KNmxK1zSqonaMMHUmAfeFQ");
define("GOOGLE_GCM_URL", "https://fcm.googleapis.com/fcm/send");
$fields = array(
'to' => $reg_id ,
'priority' => "high",
'data' => array("title" => "Android Learning", "message" => $message, "image"=> $img_url, "tag" => $tag)
);
$headers = array(
GOOGLE_GCM_URL,
'Content-Type: application/json',
'Authorization: key=' . GOOGLE_API_KEY
);
echo "<br>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, GOOGLE_GCM_URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Problem occurred: ' . curl_error($ch));
}
curl_close($ch);
echo $result;
}
$reg_id = $_POST['fcm_id'];
$msg = $_POST['msg'];
$img_url = '';
$tag = 'text';
if ($_FILES['image']['name'] != '') {
$tag = 'image';
$target_file = $target_path . basename($_FILES['image']['name']);
$img_url = 'http://192.168.225.83:8080/fcm_server/'.$target_file;
try {
// Throws exception incase file is not being moved
if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_file)) {
// make error flag true
echo json_encode(array('status'=>'fail', 'message'=>'could not move file'));
}
// File successfully uploaded
echo json_encode(array('status'=>'success', 'message'=> $img_url));
} catch (Exception $e) {
// Exception occurred. Make error flag true
echo json_encode(array('status'=>'fail', 'message'=>$e->getMessage()));
}
send_gcm_notify($reg_id, $msg, $img_url, $tag);
} else {
send_gcm_notify($reg_id, $msg, $img_url, $tag);
}
}
?>
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="../script/css/materialize.min.css" media="screen,projection"/>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Admin | FCM Server</title>
<style>body, .row{ text-align: center;}</style>
<script>
$(function(){
$("textarea").val("");
});
function checkTextAreaLen(){
var msgLength = $.trim($("textarea").val()).length;
if(msgLength == 0){
alert("Please enter message before hitting submit button");
return false;
}else{
return true;
}
}
</script>
</head>
<body>
<h1>Admin Panel</h1>
<div class="row">
<div class="col s12 m12 l2"><p></p></div>
<form class="col s12 m12 l8" action="admin.php" method="post" enctype="multipart/form-data" onsubmit="return checkTextAreaLen()">
<div class="row">
<div class="input-field col s12">
<select name="fcm_id" required>
<option value="" disabled selected>Select User</option>
<?php while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<option value='".$row['fcm_registered_id']."'>".$row['name']." <".$row['email']."></option>";
} ?>
</select><br><br>
<div class="file-field input-field">
<div class="btn">
<span>File</span>
<input type="file" name="image">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
<textarea id="msg" name="msg" class="materialize-textarea" placeholder="Type your message"></textarea>
<br><br>
<button class="btn waves-effect waves-light" type="submit" name="action">Send</button>
</div>
</div>
</form>
<div class="col s12 m12 l2"><p></p></div>
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../script/js/materialize.min.js"></script>
<script>
$('select').material_select();
</script>
</body>
</html>
5. Now update your MyFirebaseMessagingService.java
file :-
package akraj.snow.fcm; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.media.RingtoneManager; import android.net.Uri; import android.os.Build; import android.support.v4.app.NotificationCompat; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; /** * Created by Akshay Raj on on 1/17/2019. * [email protected] * www.snowcorp.org */ public class MyFirebaseMessagingService extends FirebaseMessagingService { private static final String TAG = "MyFirebaseMsgService"; NotificationCompat.Builder notificationBuilder; Bitmap image; /** * Called when message is received. * * @param remoteMessage Object representing the message received from Firebase Cloud Messaging. */ // [START receive_message] @Override public void onMessageReceived(RemoteMessage remoteMessage) { // TODO(developer): Handle FCM messages here. // If the application is in the foreground handle both data and notification messages here. // 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. String tag = remoteMessage.getData().get("tag"); String msg = remoteMessage.getData().get("message"); String img = remoteMessage.getData().get("image"); image = getBitmapFromURL(img); sendNotification(tag, msg, image); } // [END receive_message] /** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. */ private void sendNotification(String tag, String messageBody, Bitmap img) { Intent intent = new Intent(this, HomeActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); String channelID = getString(R.string.channel_id); if (tag.equalsIgnoreCase("image")) { notificationBuilder = new NotificationCompat.Builder(this, channelID) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("Android Learning") .setContentText(messageBody) .setStyle(new NotificationCompat.BigPictureStyle() .bigPicture(img)) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); } else { notificationBuilder = new NotificationCompat.Builder(this, channelID) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("Android Learning") .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); } NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Since android Oreo notification channel is needed. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelID, "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); } private static Bitmap getBitmapFromURL(String src) { try { URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap; } catch (IOException e) { e.printStackTrace(); return null; } } }
6. Now run your app
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