How can i send Firebase cloud token to my android app to open my app deeplink?
I implemented deeplink and its worked
Then config my firebase FCM and my laravel send notification to my android device. with this library
https://github.com/brozot/Laravel-FCM
i cant find any method to send link but
function sendNotification($user_id, $type)
{
$message = getNotificationMessage($type);
try {
$fcm_tokens = ClientInfo::where('user_id', $user_id)->all();
foreach ($fcm_tokens as $key => $fcm_token) {
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60 * 20);
$notificationBuilder = new PayloadNotificationBuilder();
$notificationBuilder->setBody($message)
->setSound('default')
->setClickAction('bazarshahr://customer.app/order');
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['deeplink' => 'bazarshahr://customer.app/product/39']);
$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
$token = $fcm_token['firebase_token'];
$downstreamResponse = FCM::sendTo($token, $option, $notification, $data);
$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();
// return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();
// return Array (key : oldToken, value : new token - you must change the token in your database)
$downstreamResponse->tokensToModify();
// return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();
// return Array (key:token, value:error) - in production you should remove from your database the tokens
$downstreamResponse->tokensWithError();
}
} catch (Exception $e) {
SystemLog::error(sprintf("[helpers.sendNotif] Can't send Nofication: %s (%d)", $e->getMessage(), $e->getCode()));
return false;
}
return true;
}
This feature is not mentioned in Fcm documentation but i tried some sort of tests on my own and figured out the solution: as we replied here
Instead of click_action we need to put link:
https://fcm.googleapis.com/fcm/send
Content-Type: application/json
Authorization: key={SERVER_KEY}
{
"to" : "{Firebase client token}",
"collapse_key" : "type_a",
"notification" : {
"body" : "Body of Your Notification",
"title": "Title of Your Notification"
"link": "example://my.app/products" <<-- Here is the solution
}
}