46.Send Push Notification | Firebase Messaging Flutter | Chat App

  Рет қаралды 17,670

Harsh H. Rajpurohit

Harsh H. Rajpurohit

Күн бұрын

In this video, We will enable push notification in firebase cloud messaging & also learn how we can get FCM registration token (ie. push token) & also learn how to send a test notification to our device.
Create chatting app similar to whatsapp with Flutter & Firebase.
Next Video: • 47.REST API To Call Pu...
Previous Video: • 45.Custom Alert Dialog...
GitHub Codes: github.com/Har...
Complete Playlist: • Chat App In Flutter & ...
Firebase Messaging Package: pub.dev/packag...
Cloud Messaging Official Docs: firebase.googl...
My Learning Journey: • How To Learn Android D...
Free Android (+ Kotlin) Courses 😃:
🎵 Music Player App: • Music Player App In An...
▶️ Video Player App: • Video Player App In An...
🌐 Private Browser App: • Web Browser App Course...
🔒 Firebase Authentication: • Android Authentication...
Free Flutter Courses 😃:
🅵 Flutter 3 (Beginners): • Flutter Tutorial (App ...
💬 Chat App (Firebase): • Chat App In Flutter & ...
Flutter development VS Code in Hindi.
(A Humble Request) 😊
Share Content with One Who is in Need.
Thanks for watching.

Пікірлер: 49
@harshRajpurohit
@harshRajpurohit 7 ай бұрын
For anyone facing the issue with the notifications. Credit Goes to Mafaz Khan for this Research. Observation 1: The notifications API needs to be migrated to v1 Fix: 1. Change URL to this fcm.googleapis.com/v1/projects/PROJECTID/messages:send 2. Obtain your project id from firebase-> project settings -> general (Here you can find your project ID. Observation 2: Your server key is no longer needed Fix: 1. Instead go to your Google cloud console(This is the page from where you generated the API key. 2. Search for service account, then click for your current project (It should liik like this "firebase-adminsdk-sz6nt@YOURPROJECTNAME-87ebc.iam.gserviceaccount.com" 3. Once you click on the account you will find tabs, now go to keys tab and create a new key(This should download a json file) 4. Now open the json file and copy the whole code as this will generate our bearer token Observation 3: We need extra packages and coding to generate bearer token Fix: 1. First add this package (googleapis_auth:) to your pubspec.yaml. 2 Now the coding part, create a new file in apis folder and name it access_firebase_token.dart. 3. Copy and paste the below code: Code: import 'package:googleapis_auth/auth_io.dart'; class AccessFirebaseToken { static String fMessagingScope = "www.googleapis.com/auth/firebase.messaging"; Future getAccessToken() async { final client = await clientViaServiceAccount( ServiceAccountCredentials.fromJson( { PASTE YOUR GENERATED JSON FILE CODE OVER HERE, BE MINDFUL TO NOT COPY THE CURLY BRACES JUST PASTE THE CODE IN HERE AND IMPORT THE ERRORS } ), [fMessagingScope], ); final accessToken = client.credentials.accessToken.data; return accessToken; } } Observation 4: The code needs to be changes for sendPushNotifcation function Fix: 1. Just copy the code below and imprt the errors Code: static Future sendPushNotification( ChatUser chatUser, String msg) async { AccessFirebaseToken accessToken = AccessFirebaseToken(); String bearerToken = await accessToken.getAccessToken(); final body = { "message": { "token": chatUser.pushToken, "notification": { "title": me.name, "body": msg }, } }; try { var res = await post( Uri.parse('fcm.googleapis.com/v1/projects/YOURPROJECTID/messages:send'), headers: { "Content-Type": "application/json", 'Authorization': 'Bearer $bearerToken' }, body: jsonEncode(body), ); print("Response statusCode: ${res.statusCode}"); print("Response body: ${res.body}"); } catch (e) { print(" sendPushNotification: $e"); } } Check for notification and it will work😊 Official Docs: firebase.google.com/docs/cloud-messaging/migrate-v1
@antongrekov7710
@antongrekov7710 7 ай бұрын
what
@HUTIENLAN
@HUTIENLAN 3 ай бұрын
would you like to make a new video to this part?? huge thanks
@harshRajpurohit
@harshRajpurohit 3 ай бұрын
I have already updated my github codes for it and added some comments too about how to do it (if you wish then you can refer to it).
@sohaiburrehman7257
@sohaiburrehman7257 2 ай бұрын
What is obtaining from this code? Sever key? Because the Google console is not opening so i can not enable it . And i don't have the server key
@AmreshKumar-bc7ev
@AmreshKumar-bc7ev Жыл бұрын
In KZbin i have seen lots of video but sir your explanation superb ❤️👍👍
@z_verseau
@z_verseau 4 күн бұрын
Hi sir, why we don't use API Firebase Cloud Messaging (V1). API Cloud Messaging (legacy) don't work
@harshRajpurohit
@harshRajpurohit 4 күн бұрын
You can refer to the pinned comment of this video about how to migrate to the latest way. Or you can also refer to my updated github codes as per new api. (I've added some necessary comments as well).
@tricaricoenrico
@tricaricoenrico 8 ай бұрын
Hi, good video but api legacy are deprecated
@harshRajpurohit
@harshRajpurohit 8 ай бұрын
Yep, I got to know. You can try referring to the first pinned comment for doc reference about how to migrate.
@gautamsolanki3644
@gautamsolanki3644 6 ай бұрын
please aap ese project banate rahi ye or ek project banaye with rest api all crud operation cover pleasse
@FirebaseAcount
@FirebaseAcount 3 ай бұрын
🔥🔥🔥🔥🔥 can anyone tell me how can i add a custom notification sound when receive messages in background, currently playing phones default sound? thank you very much 🔥🔥🔥🔥🔥
@sohaiburrehman7257
@sohaiburrehman7257 Ай бұрын
I am unable to generate the server key The google console giving me error
@harshRajpurohit
@harshRajpurohit Ай бұрын
What error it shows.
@dhokiyaharsh
@dhokiyaharsh Ай бұрын
Sir, Cloud Messaging API Disabled? How to Send Push Notification And how to get server key
@harshRajpurohit
@harshRajpurohit Ай бұрын
You can refer to the pinned comment of this video about how to migrate to the latest way or you can also refer to my updated github codes as per new api (I've added some necessary comments as well).
@e.n.d5103
@e.n.d5103 11 ай бұрын
I have followed until the end but why is the notification not appearing and why is the permission request also not appearing?
@harshRajpurohit
@harshRajpurohit 11 ай бұрын
Actually permission request is for Android 13 or higher, for lower androids it works without it. Have you tried sending test notification from firebase using your device id.
@kendallfernandez9410
@kendallfernandez9410 3 ай бұрын
ere un makina
@luisrieker3547
@luisrieker3547 5 ай бұрын
why is my app logo only a white circle, although i changed it in AndroidManifest and image is transparent
@harshRajpurohit
@harshRajpurohit 5 ай бұрын
It's a bit difficult to say why it's happening rather you can refer to the article below for more details of how to change it. stackoverflow.com/questions/46676014/how-to-change-the-android-notification-icon-status-bar-icon-for-push-notificatio
@tushiyahsolutions8000
@tushiyahsolutions8000 Жыл бұрын
Do you have this tutorial in English?
@harshRajpurohit
@harshRajpurohit Жыл бұрын
Nope buddy.
@parasverma7713
@parasverma7713 Жыл бұрын
Sir mene apne mobile jb ye sb krke app run kra to ek push token generate hua or us account me merko notifications aari thi and fir mene pehle wale account ko log out kiya or dusre account se login kiya fir v same hi pushtoken generate hua esa ku? Or ye firebase se jb aapne test notification bheji to firebase ko pta kese chala ki konse account me notification bhejni h ? Firebase jo hamara user login h app se uska pushtoken read krke use notification bhej rha hai kya? Or agr wo push token read kr rha h user ka to kese kuki hmne to koi code ni likha push token read krne ka
@harshRajpurohit
@harshRajpurohit Жыл бұрын
Regarding the same push token: Actually on a single device generally the same push token is generated. Regarding test notification: We're passing push token while sending test notification i.e. how firebase knows whom to send.
@AmreshKumar-bc7ev
@AmreshKumar-bc7ev Жыл бұрын
Sir main iss WeChat project main mannual registration bhi karna chahta hu to chatUser I'd time & is_online kaise request kar shakte ??
@harshRajpurohit
@harshRajpurohit Жыл бұрын
Actually whether you implemented google sign in or any other registration method (and you can use anything as id like email to), you just need to setup firebase cloud firestore and you can create and update any filed you like.
@adilhesenov2962
@adilhesenov2962 Жыл бұрын
perfect
@ramakantpandit8507
@ramakantpandit8507 Жыл бұрын
sir i am having this error 'Some input files use or override a deprecated API.' and nothing is being shown in the push notification log
@harshRajpurohit
@harshRajpurohit Жыл бұрын
Deprecated api error is okay but push notification should show some logs if you've printed it. Maybe an error or something. Have a look at it calmly.
@jingyipua773
@jingyipua773 10 ай бұрын
May I ask is the app noti still able be triggerred when the app is being terminated (closed)?
@harshRajpurohit
@harshRajpurohit 10 ай бұрын
Yep, push notifications has nothing to do with app running in the background.
@jingyipua773
@jingyipua773 10 ай бұрын
@@harshRajpurohit sorry, my meaning is the app is not running at all. There are three state of app: -active (in app) -inactive (background) -terminated (app is exit and closed) Will your method able to handle push noti on three app states?
@harshRajpurohit
@harshRajpurohit 10 ай бұрын
Mainly it handles for terminated & somewhat for background state but for active state we need to use local_notification package and listen for notification receive and then show our custom notification.
@fahadislam8975
@fahadislam8975 Жыл бұрын
sir ap na jo api postman mai test ki wo kha sa li
@harshRajpurohit
@harshRajpurohit Жыл бұрын
Actually I got it after searching a lot on google and stacks overflow.
@arnabsadhukhan89
@arnabsadhukhan89 Жыл бұрын
Bhaiya mujhe yea error dikha raha hai [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: LateInitializationError: Field 'pushToken' has already been initialized. pls help kijiye😩😩
@harshRajpurohit
@harshRajpurohit Жыл бұрын
If you've written the final in front of pushToken variable in the chat_user model then just remove it.
@arnabsadhukhan89
@arnabsadhukhan89 Жыл бұрын
@@harshRajpurohit Thanks a lot bhaiya❤👍
@ankitpurohit18
@ankitpurohit18 Жыл бұрын
👍👍👍👍👍
@deepakdalai9905
@deepakdalai9905 Жыл бұрын
🙂
@yasirgul914
@yasirgul914 10 ай бұрын
E/FirebaseInstanceId(20797): Topic sync or token retrieval failed on hard failure exceptions: PHONE_REGISTRATION_ERROR. Won't retry the operation. E/LB (20797): fail to open file: No such file or directory E/FirebaseInstanceId(20797): Topic sync or token retrieval failed on hard failure exceptions: PHONE_REGISTRATION_ERROR. Won't retry the operation. E/flutter (20797): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_messaging/unknown] java.io.IOException: PHONE_REGISTRATION_ERROR
@harshRajpurohit
@harshRajpurohit 10 ай бұрын
Try changing the version of google gsm in build.gradle (inside android/app folder) to 4.3.15 (maybe it can work) . Line to update: classpath 'com.google.gms:google-services:4.3.15'
@FirebaseAcount
@FirebaseAcount 3 ай бұрын
🔥🔥🔥🔥🔥 can anyone tell me how can i add a custom notification sound when receive messages in background, currently playing phones default sound? thank you very much 🔥🔥🔥🔥🔥
@harshRajpurohit
@harshRajpurohit 3 ай бұрын
Actually you have to do it separately for android and iOS but you can refer to the article below: stackoverflow.com/questions/54002617/custom-sound-push-notification-does-not-work-flutter/54003722#54003722 (I know it's a bit complex but during its implementation, you will learn a lot).
47.REST API To Call Push Notification | Firebase Messaging Flutter | Chat App
10:17
Inside Out 2: ENVY & DISGUST STOLE JOY's DRINKS!!
00:32
AnythingAlexia
Рет қаралды 14 МЛН
哈莉奎因怎么变骷髅了#小丑 #shorts
00:19
好人小丑
Рет қаралды 55 МЛН
💩Поу и Поулина ☠️МОЧАТ 😖Хмурых Тварей?!
00:34
Ной Анимация
Рет қаралды 2,1 МЛН
Flutter Push Notifications com Firebase em 2022
23:36
Prof. Diego Antunes
Рет қаралды 18 М.
💬📱 Minimal Chat App • Flutter x Firebase Tutorial
1:05:12
Mitch Koko
Рет қаралды 83 М.
Flutter Android, Web & iOS Push notifications with Firebase messaging
50:54
📱Android Push Notifications • Flutter x Firebase Tutorial
12:39
Smart Push Notifications with Flutter & FCM
11:10
Fireship
Рет қаралды 217 М.
49.Modal Bottom Sheet With Divider In Flutter
17:27
Harsh H. Rajpurohit
Рет қаралды 3,1 М.