Hello everyone, today I am going to teach you all how to create dialog from an Admin App to the User app through Firebase Database using Sketchware.
Linking your Sketchware Project to Firebase
This is the first thing to do before any other thing else cause the Project needs to be linked to firebase before you can use any Firebase service.
So I’ll just summarize the whole process of linking your Sketchware app to firebase.
- Create a new Sketchware project and and take note of the package name, login to your Firebase Console and create a new project and then a new app. While creating a new app, make sure the package name matches your newly created Sketchware project’s package name.
- After creating the app in Firebase, while the verification is going on, minimize and move to Sketchware and open that newly created project then click on the Drawer or the three dots in the left, then click on Library > Firebase > Link project to Firebase > Open Firebase Console.
- Now back in the Firebase Console, Go to app settings and copy your project ID, App ID and web API key, then minimize back to Sketchware and paste them in the required areas and save. Then your app is successfully linked to Firebase.
NOTE: Creating dialogs from an Admin App to the User app will only work if :
- The package name of both Apps are the same.
- The app is combined to be one app in Firebase by adding the same project ID, app ID and web API key to both projects.
Programming the User/Receiver application in Sketchware
First we add a dialog and Firebase Database component to the project, make the Firebase Database , then we create a dialog in the ‘onChildAdded’ event that comes with Firebase Database component.
Now, this is very easy all we have to do is create dialog with specific keys which their values will be displayed when the Child is added. First create a map variable and put these blocks you see in the picture below.
We still added Shared Preferences to prevent
the Dialogs from showing more than once a to a user.
Programming the Admin Application
Now we are going to program the Admin Panel/Broadcaster, you should know you are the only one to use this app so you don’t necessarily need to design it.
After you have dropped the EditText and button, move the Logic area > View > select the button ID ( ex. button1 ) and create a clickListener for it. Put these blocks in the screenshot below.
Then for the “delete” button add this
How to use the Admin and User applications to produce great results
Now the app is up and running, using the app is very easy but all you have to do is always change the value of the key: “code” anytime you are making a dialog.
And then anytime you want to create a dialog, here is how you do it.
- Open your Admin app
- If you have sent a dialog before, you’ll delete the “start” value.
- Set your unique code,:key: code, value: //your unique code ( it should always be different)
- Set your Dialog title: key: title, value: //your dialog title
- Set your Dialog message: key: message: value: //your message
- Send your dialog: key: start , value: yes