Skip to main content

Firebase auth in Sketchware for Login Activity

To create a login activity using Firebase Auth in Sketchware, follow the steps given below. This method uses Firebase authentication service for creating login.

1. In your Firebase account, go to Firebase authentication.
2. In Firebase authentication web set-up, go to SIGN-IN method, and enable Email/password and Anonymous.

3. Go to Project settings in your Firebase project and copy the Web API Key, Project ID, and App ID.
4. Paste the Project ID, App ID, and Web API Key in your project in Sketchware, in the Firebase settings.

5. On the MainActivity page add a File Shared preferences component user:user and an Intent i. Also add a Timer and a Firebase Auth testlogin.



6. Create a new page login.xml with Activity called LoginActivity.

7. In onCreate event of MainActivity use blocks as shown in image below.

It identifies main page with File user key page. It also checks if user is logged in to FirebaseAuth.
If user is logged in then other blocks are executed.
If user is not logged in, he is taken to LoginActivity using Intent i.

8. On LoginActivity VIEW area,
* add two Linear(H) loading_linear and linear3.

* In linear3 add two Buttons button2 and button3 for Sign in and Sign up respectively.

* Below linear3 add two Linear(V) login_linear and register_linear.

* In login_linear add edittext3 and edittext4 for email and password respectively, and add a Button login_button for Sign in.

* In register_linear add edittext7, edittext6 and edittext5 for nickname, email and password respectively. Also add register_button for Sign up.

See the image below.

9. In LOGIC area of LoginActivity, add a new File Shared preferences component user:user (same as in MainActivity),
a FirebaseDB component user_id:userid, and a Firebase Auth component testlogin (same as in MainActivity).


10. Add a List Map map1 and a String list uid.

11. Also add a Map variable map_var, and a number variable n.

12. In onCreate event of LoginActivity add blocks as shown in image below.
These blocks identify page by setting value login to file key page. They also make loading_linear VISIBLE and other linears GONE.

13. On button2 click add blocks shown in image below. These blocks make login_linear visible, and button2 red.

14. On button3 click add blocks shown in image below. These blocks make register_linear visible, and button3 red.

15. On register_button Click, add blocks as shown in image below.

These blocks check if the EditText fields are empty. If they are empty it toasts a message. If not empty, it registers the email and password of user to Firebase Auth and makes loading_linear visible.

16. Add event Firebase Auth: onCreateUserComplete and use blocks as shown in image below.
If the user is registered successfully, these blocks push his FirebaseAuth Uid, and his nickname to Firebase DB user_id. If registration fails, these blocks make register_linear VISIBLE.

17. Add a new event FirebaseDB on child added. In this event use blocks as in image below.


These blocks get data from Firebase DB to List Map map1, and then create a String list uid from all the uid in List Map map1, and make login_linear VISIBLE.

18. On  login_button click use blocks as shown in image below.

These blocks Sign in user using Firebase Auth and make loading_linear visible.

19. Add event Firebase Auth: onSignInUserComplete and use blocks as shown in image below.

If user is signed in using Firebase Auth, these blocks save his nickname, and move him to MainActivity by Finishing LoginActivity.

20. Add onBackPressed event and use following codes in it.
21. Again in MainActivity, add onStart event, and use following blocks.

22. In VIEW area of MainActivity add a button (button2) for Sign out, and on the event of button2 click, use following blocks.

23. Save and run the project.

Here the nickname entered by user and his Uid created by Firebase Auth, are saved in Firebase realtime database.

Comments

Popular posts from this blog

Create Music Player app in Sketchware

To create a Music Player app in sketchware, follow the steps given below. 1. Create a new project in Sketchware. 2. In VIEW area on main.xml, add a ListView  listview1  with height wrap_content, and weight 1. Add a SeekBar  seekbar1 , an ImageView  imageview1 , and three TextViews  textview1 ,  textview2 , and  textview3 , as shown in the image below. 3. Create a CustomView  mycustom.xml  and add a TextView  textview1 , and an ImageView  imageview1  in it. For listview1 select mycustom.xml as it's customView. 4. Add a MediaPlayer component  mp , a Shared Preferences component  sp:sp  and a Timer component  timer . 5. Create six More Blocks  MPcreate(pos), MPstart , and  MPpause  for the MediaPlayer and  searchFolders ,  getFileList in [filePath]  and  extra . 6. Add three number variables  n, r  and  songPosition , and five String variables  currentfile ,  songMinutes ,  songSeconds ,  folder ,  folderName . Also add a List String  folderList,  List String  fileList  and a List Map

Admob rewarded video Ads in Sketchware

To integrate Admob Rewarded Video Ads to a Sketchware project, follow the steps given below. Prerequisites An Android project (Sketchware project) Account in Admob Always place the test ad unit ID before placing your ad unit ID. App ID and ad unit ID can be obtained by registering the app on Admob. But for using test ads no registration is required. Do not click on your own Ads. 1. Create an android project in Sketchware. 2. Add the app to your Admob account. For your app, generate an ad unit ID for Rewarded Video Ads. 3. In Sketchware project, navigate to  Library Manager  and open Admob settings. i. Click on Add manually and add the ad unit ID generated on Admob website, or use test ad unit ID ca-app-pub-3940256099942544/5224354917. ii. If you are not using any banner or interstitial ad units, select the same ad unit ID for both banner and interstitial ads. iii. Add Test Device automatically shown by Sketchware. iv. Save it. v. Switch ON Admob and AppCompat and design. 4. In this exa