In my android app a new user initially registers himself with the app then if the user is approved by the admin from back-end then only he will be able to login.Now,what i want is as soon as admin approve the user, a notification should appear in android mobile telling the user that now he can login successfully as he has been approved.I have stored my data in MySQL database in web server.Now i have no idea how to implement this.Any help would really be appreciated.
Asked
Active
Viewed 1,625 times
5
-
what you have tried for you? – Karthi Oct 22 '16 at 05:54
-
http://stackoverflow.com/questions/25859898/sending-push-notifications-to-multiple-android-devices-using-gcm – AkshayP Oct 22 '16 at 05:57
-
1I don't have idea how to implement it. – user6704378 Oct 22 '16 at 05:57
2 Answers
0
You should have to store the user's device token while user register in the system. And when admin make the user active from backend you should have to send notification to user by FCM service on the device token.
If you don't have idea about FCM please visit : https://firebase.google.com/docs/cloud-messaging/concept-options
Please found the push notification sending code from PHP below.
function sendFCMPushnotification($arr) {
$device_token = $arr['device_token'];
$message = $arr['message'];
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array (
'registration_ids' => array (
$device_token
),
'data' => array (
"message" => $message,
"sound" => "default"
),
'notification' => array(
'body' => $message,
'title' => 'ProjectName',
)
);
$fields = json_encode ( $fields );
$headers = array (
'Authorization: key=' . "PUT_YOUR_FCM_Key",
'Content-Type: application/json'
);
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
$result = curl_exec ( $ch );
var_dump($result);
curl_close ( $ch );
}
$arr = [
'device_token' => "PLACE_YOUR_DEVICE_TOKEN",
'message' => 'PLACE_YOUR_MESSAGE',
];
sendFCMPushnotification($arr);

Rahul Patel
- 5,248
- 2
- 14
- 26
0
First of all integrate push notification service in you app. Then from server side you need to send push notification as you approved credential so user will get push notification on app.

Ronit kadwane
- 524
- 1
- 5
- 22