push notification firebase android studio || Migrate from legacy FCM APIs to HTTP v1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back it's me rajin Sharma and in this tutorial I'm going to show you that how can we integrate new Firebase messaging service which is HTTP V1 API and I know that a lot of my subscribers are facing problem while integrating to this new service okay and the problem is that when you are if you are using the old Firebase fcm service and you try to upload the application on Play Store so it will show an error that you cannot upload the application because you are using server key and this uh service will be down by this year June okay so I know that you all are facing problem that what are the changes that you have to do in the code in order to implement this new functionality so in this video I'm going to show you the complete code complete process step-by-step tutorial that how can you really do it and trust me this video is very simple all the codes I will show you on the screen and if you want the if you want these codes you can simply join the membership it's very affordable just 60 INR or you can say $1 USD you will get all the codes and everything fine okay because I will show you step by step procedure do not skip any part of the video watch this complete video and you will be able to implement this new functionality of Firebase and you will be able to send notifications to specific user okay so without wasting time let's start so guys very first of all what you have to do is you have to open your Firebase account so you can see that I will show you this demo in the project chat it okay so you will be able to send notification to specific user while chatting okay so they will be able to see the new message so what you have to do here is you can see that you have to open your project chat it and simply go to Project settings and then you have to click on this service accounts and then you have to select the option Java and then simply click on this generate new private key I have already generated a new key that's why I will not generate another one okay but you guys if you are watching this for the first time so you just have to Simply click on this generate new private key and after that guys you will get a file like uh this you can see that chat 8031 Firebase admin SDK xpq so you can see you will get a file like this okay so after that what you have to do is you have to Simply open this file in Visual Studio code or any other editor in case if you have okay so just open this file and then you will see a code like this okay and it contain all the information that you need in order to get the uh in order to get token for sending specific for sending notifications okay so what you have to do is you just have to Simply cr+ A and control+ C okay and simply close this now after that you have to come back to Android studio and uh before that what you have to do is you have to add this dependency which is com. gooogle or Google or Library o or 2/ HTTP colon 1.1 9.0 so you have to add this dependency in your gradal I will provide this in description and you can also get it in in source code okay guys so after adding this dependency you have to Simply click on sync now and after syncing this you have to add two more lines which is this packaging options exclude meta INF dependencies packaging options and you have to click uh you have to add these two lines in your uh gradel build okay and then after that again you have to click on sync now now after doing this part what you have to do is you have to create a Java class of name access token and you can see that here we have this access token class and I will show you the complete code I will not hide anything okay so you can see public class xess token and private static final string which is uh Firebase messaging scope and here you have to pass the latest URL for getting the you know it's a URL that was added in the documentation of fcm okay migration from U I don't know what it is called uh fcm to http V1 API so you have to use this URL okay for generating the access token which we will need for sending notification by server okay so how can we do that you just have to Simply write down this URL I will also provide this in description and also in source code the easiest way is you can simply visit rajen sharma.com pay 60 irr or $1 and you will get this complete coding so you don't have to worry about all these you know minor mistakes in the code you can simply get the complete code just $1 60 INR and if you will pay 200 or you can say $3 USD so I will give you complete ZIP file and yeah so after um giving this a string URL okay what you have to do simply create a method public string get access token use try and catch and uh you know guys the U I mean the code that we have copied here so after copying it what you have to do you have to create a string of string Json string and simply between this string you have to paste that complete thing okay simply contrl plus a contrl + C and paste it here and it will look like this okay I I have hidden this code because it is confidential information but you have to Simply do this okay now after that you have to Simply use input stream stream by array input stream so we will simply convert this string okay and then we will use this string for generating the access token and uh for that you can see that we have already added this Google credentials service library for Access for generating the token and this is how we are generating here okay uh Google have also their own documentation in case if you want you can refer to there but uh it will only create problem for you because if you follow this procedures you will get everything done in minutes and then you will be able to send notifications okay and for source code visit.com and this part of code you have to write for getting the access token and in the Cat part you can simply show a message that error we are not able to get it okay and one more important thing uh open your main activity and uh here you have to write down these two lines of code strict mode thread policy thread policy and permit all do build then strict mode set thread policy policy if you will not write these two lines of code so what will happen when you will try to call this method when you will try to execute this part of code inside this uh sorry when you try to execute this part of code of access token Java class so it will simply throw an error and you will not be able to get the access token so you have to write these two lines in your main activity or any activity which is called very first time I mean you can say it's a very first step activity that a user will go when they will open the application so you just have to Simply call these two lines okay now uh this was a complete code for this uh access token class okay I have shown you everything you can pause the video write down the code and I will also show you the uh values that we are importing here util log all credentials common collect list by ter input IU expection uh IU exception input stream Char set standard Char set okay now after that what you have to do is you have to create a new Java class which is send notification just uh forget this previous which is fcm notification sender we don't need it anymore okay and uh create a new Java class which is send notification and after creating it what you have to do simply derive these four values user fcm token title body context and post URL so guys previously we were using uh different URL for sending notification but this time the Firebase have updated now the URL is fcm ap.com V1 project and here you you have to pass the project ID of your project and you will get it here in this uh Firebase okay here you can see that I have this project ID so I will simply copy it and you have to use your own project ID for passing here okay rest of the uh URL will be same only you have to update this project ID okay and after updating this project ID simply create a method which is public set notification call these four values and initialize it after that you have to create a method now the important part comes okay send notification method inside it simply create a reest q and for that you have to I mean we already have added the Vol Library so I don't think I have to show that part of code so you just have to add the Vol library and then after that you will be able to use its services and then you can simply uh use this API for sending notification okay and then inside this try method we will simply create a Json object and we will store all the values that we want to share like title body token notification and message object so you can see this part of code that we are doing and uh then guys now you can see that here you have to Simply uh call this access token class method for getting the access token and it will be updated you can say after some time okay so it is not like if you will fetch it once so it will work forever it will keep updating on hourly basis on you know it's I have not checked the details but yeah it will uh not remain same all the time it will keep updating so after that you have to create a map string so this code was you know previously so in the Firebase fcm notification sender we have same code almost okay so you just have to Simply use header put content type application Json authorization then new thing that you have to write which is bror it is very important okay I have seen this in the documentation so you have to add this for sending notification and then here you have to pass the access key that we have generated inside this access token class so after that simply return header and then simply add this Vol request okay guys and in the exception part simply show a toast message that we have some error okay okay so this was a complete code of this send notification class okay after that you have to use call this Firebase messaging service so this class code is quite simple nothing is very changed okay only you have to comment this two part two lines of code okay and instead of this you just have to Simply write builder. set small icon R probable icon R probable icon that's all you have to do otherwise rest of the code is same you don't have to make any other changes now I will show you how can you send or call this method so simply open message activity [Music] um here we have the message activity and inside uh we have a method which is send notification yeah here it is so inside this send notification we will try to fetch the token very first of [Music] all where is it where is it where is it yeah yes so guys you can see that inside this on create very first of all we will fetch the token that we have stored on the very first uh place here you can see we are storing Firebase messaging get instance get token add on complete simply store this value like this here and inside this message activity we will fetch it Firebase messaging get instance get reference tokens token of receiver user ID and then like this okay so this is how we can uh fetch the token and inside this uh method send notification you just have to use a Handler Handler then run send notification notification sender new send notification sender pass user token of the user who you want to send this notification and then s name sender name to uppercase message SMS message activity. this notification sender. send notification message it set null and uh delay this uh code for 3 milliseconds okay so this was the complete code that you have to do and one more thing for now so guys now for showing you the demo what I will do is I will pass current user token instead of receivers token so you will see the demo so I don't have to run the application in two devices I will simply pass sender user ID okay so if I will send any notifications so I will receive I mean if I will send a message so I will receive the same notification and that is not a bug actually I'm doing it for showing you the output okay so now I will run this application in my physical device and let me turn on the screen recorder so you will see the complete update so guys now for source code of this complete tutorial you have to simply visit Rajan sharma.com and I also have a PayPal account my new PayPal account so do not send money on the old one because I have closed that account for some reasons so send money on new PayPal account and you will be able to get all the codes okay and if you will join third level of membership so I will give you the APK file of this complete project second level I will give you the file and first level I will I know but I did bus that is the easiest way to make things simple this is business so now the app is ready to run and launching on devices so now you can see that uh the app is running absolutely fine there is no error and uh now if I will simply open this uh messaging activity and I will send a message like uh hello sir testing notifications send it and uh you can see hello sir testing notification it is I'm receiving the notification because I have passed sender users token okay so you can see this the functionality is working absolutely fine and we are receiving notification by using HTTP V1 API new Firebase service so I hope you guys like this tutorial and please like share and subscribe my channel and do not forget to press press the Bell icon so you will never miss any update thank you for watching
Info
Channel: Rajjan Sharma
Views: 8,048
Rating: undefined out of 5
Keywords: fcm api to http v1, migrate from legacy fcm apis to http v1, fcm http v1 api example, http v1 api fcm, fcm http v1 api postman, fcm http v1, migrate from legacy fcm apis to http v1 flutter, firebase http v1 php, flutter fcm http v1, send messages via the http v1 api, firebase cloud messaging api (http v1)
Id: TXiKgsOh_qw
Channel Id: undefined
Length: 13min 35sec (815 seconds)
Published: Thu May 16 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.