Android Push Notification Using Firebase Cloud Messaging
Steps to implement FireBase push notification in Android
1: Import the code of FCM
4: Now put your app name and select your country.
6: Now you have to enter your projects package name and click on ADD APP.
7:After clicking add app you will get google-services.json file.
Now here Console work is finish
Adding Firebase Messaging to Your Project
1:Now come back to your android project. Go to app folder and paste google-services.json file.
Don’t forget to change the app id to your package name in app gradle
Sending Push Notification using Firebase Console
1:Go to firebase console and select the app you created.
2:From the left menu select notification.
3:Click on new message.
4:Enter message, select single device and paste the token you copied and click on send.check your device
Congratulation you have configured the FCM in your app
If any trouble please refer the link Firebase Cloud Messaging Tutorial
PHP code to send push
PHP code to send push
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array
(
'message' => 'here is a message. message',
'title' => 'This is a title. title',
'subtitle' => 'This is a subtitle. subtitle',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
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 );
curl_close( $ch );
echo $result;
Happy coding
Comments
Post a Comment