Android PushNotification Using Firebase and PHP 2021 | Android Studio | Java | PHP | Firebase

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome to my channel today we are creating a project called push notification for our android app uh using the firebase and with the help of php we will send the message remotely to our android app so let's get started guys so our first step is to create a firebase project we will follow the step by step guide as well as you have seen we have a one to eight step so let's do the first step so first we have to go to the console.firebase.google.com where we have to sign in so i will login into my account so we have to create a firebase project right now i will named it as push notification project hit continue we don't want any google analytics services right now create project this will take some time now our next step is to create the android app so head back towards the android app android studio okay we have to create a new project we are selecting the empty activity next and then we called as a push notification project then i just change the package name finish this will take some time as the gradle is building so now we have to follow the third step right now we are going to tool firebase and then we are using the google assistant we are using the assistant for cloud messaging so set up firebase cloud messaging now we have to connect the app to our firebase project so this is our project push notification project so we just have to simply click just hit connect okay so now our firebase project is connected to our app just refreshed it our page now go back to our main activity then we just have to follow the second step which add some dependencies in our project so our dependency is added now this third step is device registration token so this is the depreciated method and we don't use it right now as we don't want any services in our manifest of step number three so we just keep it but we have to do uh we have to generate token anyways so we are going and we are following the different step for to get a registration token so private void generate okay git token firebase messaging dot get instance dot get token dot add on complete list now now we will implement on complete listener and check if task is filled so we don't get any token if task is successful then we get a token okay so i comment it if task is filled then if task if not us dot is successful then we will show in our log that our registration token is filed so fail to get token now if successful then we will catch the token into our string variable so i will comment it if token let's create the constant field for tag so i named it as push notification now i will log as a token so we can get a successful token result now i just call it and run it let's check it out okay so we got the token on on complete listener so we just copy it or just let it here now we generated token created file messaging services for the class we do it now now let's click on the project i will add the package named as notify or notification now i create a new java class that's my firebase messaging service [Music] okay extending firebase messaging service now i just want any uh just one method on message received which i will override this okay we have just follow the four step now we have to declare in the following of the manifest file on our right side of the assistant window of firebase we just logged it now that our message bit notification target body and gate title also now i just create a constant field for attack i just named it as a push notification push notification okay i just had doing manifest now just copy all the things from the firebase assistant and paste it here just change the android dot name to point out our firebase services i will comment it as a firebase messaging services now we will just go to main activity now we have to create a channel so our next step is five the build notification channel so i just have some link which we will open in our browser let's let me copy the link okay so this is our developer.android.com guide document so i just want to create a notification channel so i grab the whole code ctrl c and ctrl v here yeah right here now i just import some classes here import okay all right just remove the comment now we just add the hard coded name here for this notification channel okay so this is the firebase native channel and the description is [Music] we write description as uh receive fab is notification okay now we have to create a channel id here so i just create a constant field and channel id is a 101 in the string field so i just put the inverted comma here grab the firebase notification channel okay and now we have to create a notification channel method and just have to call about the gate notification okay now we just have to show the notification right here so i just create a method called as shown notification private void show notification okay in the parameter i will type title and the message so whenever we use the method so we get the parameter name as title and the message so i grab the below code and paste it here and import the services classes so i just change it here the main activity dot class now just import the pending notification put notification copy it okay now we say the title of the parameter in our dot set content title [Music] i see launcher background i just inputted our title a variable title name and in the below set content text we just use the message variable okay i just want to so we just need a channel id this must be the same as the main activity that we mentioned earlier so i just put it 101 and just call show notification remote dot message dot get notification dot get title and get body okay that's it for now now next step we just need the pillow code so we just have to invoke the notification let's import it notification id i typed it as one let's save it let's run it now in the firebase notification notif channel this is our name of notification so let's copy it and go to the firebase console let's reload now just type it notification title notification text hello from the firebase project so next step is target the app we just use the package name next and here we have to mention the notification channel here so just copy it and paste it here okay so we back go back to the notification i don't want to enable okay let's close it okay send message now this is our device code so we just test it here yeah we got it notify hello from firebase project okay so we have done here for the android part look at that this is the another one and when we click on the project we just head back towards the main activity now we just created a build notification channel tsd app now we have to create a php script so for php script i just want to go to the windows series amp htdocs demos now here i will create a text notify.php i just opened in in the [Music] code where is the open with code i just work uh run the samp server let's start it okay so here we write the code first of all we just test it let's test the our php app php script localhost 808 demos notify.php okay so okay i just forgot the php tags so i'm php open and php close the service okay so we have got a running php script now here we are just create a function notify and then the parameters just do and data okay so we open the another tab and open the new link here okay so link is open now we have to build the erase request so we just click on the rest and copy the call path go to php our first site just we have to convert it just copy it and paste it here i'll just format the code so here is our api key which is blanket right now now the url and the field path field variable okay we just use the another link here so http firebase fcm.google api dot com fcn same so this is all the url here [Music] we just delete it [Music] drop the url variable here we don't want it right now we just nailed our fill okay so we have to change the pair to key and mention the api key here okay now we just need to call the function dollar to in dollar to we need a device id which we generated in our android studio and the data equals to array we just need a title and the notification so the title is our the above title [Music] okay so so we just call these greetings and in notification or body we just need i from php script just open the android studio copy the whole device id and paste it here just call the function or the function name notify okay notify dollar to and dollar data okay we just printed some message here sent we just have to mention the field so let's add the fill data here json encode harry to how to variable here and in notification we just need a data variable here okay let's have the application let's go to the browser refresh it okay so we got the notification here now let's go to the step we generated a token created firebase messaging then build channel tsd app create a php script successfully and invoke the php script successfully so our app is in working right now that's it right now guys don't forget to subscribe my channel if you like the content so okay guys bye bye see ya
Info
Channel: Software Developer
Views: 15,727
Rating: undefined out of 5
Keywords: Android Studio, PHP, Firebase, 2021, PushNotificaiton
Id: 4zdTRFypBMg
Channel Id: undefined
Length: 21min 42sec (1302 seconds)
Published: Sun Mar 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.