#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
#AdditionalJar: com.google.android.gms:play-services-base
#MultiDex: True
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Dim gs_verificationID, gs_phoneNumber As String
Private authphone As FirebaseAuthPhoneWrapper
Dim gb_phoneVerificationSuccess As Boolean
Private auth As FirebaseAuth
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Private fet_setphonenumber As EditText
Private setPhoneNumber As Button
Private rp As RuntimePermissions
Dim gs_signInMethod As String
Dim ime As IME
Private EditText1 As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("er")
Try
If FirstTime Then
ime.Initialize("e_ime")
gb_phoneVerificationSuccess = False
If CheckForGooglePlayServices = True Then
ToastMessageShow("Google play services active!",True)
End If
rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
MsgboxAsync("Phone access permission not allowed!", "Alert...")
ExitApplication
End If
read_signInMethod ' get preferred method from firebase.ini
End If
authphone.Initialize("authphone")
Dim ls_phoneNumber As String = getPhoneNumber
If ls_phoneNumber <> "" Then gs_phoneNumber = ls_phoneNumber
Catch
Log(LastException)
End Try
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub authphone_oncodesent(success As Boolean, verificationid As String)
'--------------------------------
Log("q1")
If success = True And gb_phoneVerificationSuccess = False Then
gs_verificationID = verificationid
Log("q2: " & gs_verificationID)
End If
'''''Log("authphone_oncodesent success" & success)
End Sub
Sub authphone_phonesignedin(success As Boolean, User As FirebaseAuthPhoneUser, info As String)
'--------------------------------
If success = True Then
authphone.currentToken()
gs_signInMethod = "phoneLogin"
End If
End Sub
Private Sub setPhoneNumber_Click
Dim ls_phoneNr As String = fet_setphonenumber.Text.Trim
If ls_phoneNr.StartsWith("+") = False Then
MsgboxAsync("Please digit complete Phone number using +xx prefix!", "Alert...")
Return
else If fet_setphonenumber.Text.Length <= 9 Then
MsgboxAsync("Please digit complete Phone number using +xx prefix!", "Alert...")
Return
Else
gs_phoneNumber = fet_setphonenumber.text
authphone.startPhoneNumberVerification(gs_phoneNumber)
save_signInMethod
End If
End Sub
Sub save_signInMethod
'-----------------------
Dim MapConfig As Map
MapConfig.Initialize
MapConfig.Clear
MapConfig.Put("authSignInMethod", gs_signInMethod)
If gs_phoneNumber <> "" Then
MapConfig.Put("authPhoneNumber", gs_phoneNumber)
End If
File.WriteMap(File.DirInternal, "firebase.ini", MapConfig)
End Sub
Sub getPhoneNumber As String
'--------------------------------
Dim pID As PhoneId
Dim phonenumber As String
phonenumber = pID.GetLine1Number
Return phonenumber
End Sub
Sub CheckForGooglePlayServices As Boolean
'---------------------------------------------
Try
Dim GoogleApiAvailablity As JavaObject
GoogleApiAvailablity = GoogleApiAvailablity.InitializeStatic("com.google.android.gms.common.GoogleApiAvailability").RunMethod("getInstance", Null)
Dim context As JavaObject
context.InitializeContext
Dim li_googlePlayServices As Int = GoogleApiAvailablity.RunMethod("isGooglePlayServicesAvailable", Array(context))
If li_googlePlayServices <> 0 Then
GoogleApiAvailablity.RunMethod("makeGooglePlayServicesAvailable", Array(context))
Return False
End If
Return True
Catch
Log(LastException)
End Try
End Sub
Sub read_signInMethod
'-----------------------
Dim ls_tempKey As String
Dim MapConfig As Map
MapConfig.Initialize
If File.Exists(File.DirInternal,"firebase.ini") = False Then
File.WriteMap(File.DirInternal, "firebase.ini", MapConfig)
End If
MapConfig.Clear
MapConfig = File.ReadMap(File.DirInternal,"firebase.ini")
ls_tempKey = ""
For i = 0 To MapConfig.Size - 1
ls_tempKey = MapConfig.GetKeyAt(i)
Select ls_tempKey
Case "authSignInMethod"
gs_signInMethod = MapConfig.GetValueAt(i)
Case "authPhoneNumber"
gs_phoneNumber = MapConfig.GetValueAt(i)
End Select
Next
Log ("Method: " & gs_signInMethod & CRLF & " Phone: " & gs_phoneNumber)
End Sub
Sub Auth_SignedIn(User As FirebaseUser)
'---------------------------------------------
If User.DisplayName <> Null Then
Log("google SignedIn: " & User.email)
Log("UID: " & User.Uid)
Log("User name: " & User.DisplayName)
ToastMessageShow("Welcome: " & User.email , True)
gs_signInMethod = "googleLogin"
save_signInMethod
''''' Activity.RemoveAllViews
''''' Activity.LoadLayout("main2")
''''' labelLogInMethod.Text = "Logged in with Google"
''''' LabelUser.Text = "user:" &User.DisplayName & CRLF & "email: " & User.Email &CRLF & "UID/Token" & CRLF & User.Uid
End If
End Sub
Private Sub Button1_Click
Try
Log(gs_verificationID)
authphone.verifyPhoneNumberWithCode(gs_verificationID, EditText1.text)
Catch
Log(LastException)
End Try
End Sub
Sub gb_phoneverification(success As Boolean, info As String)
Log(success)
End Sub
Sub authphone_phoneverification(success As Boolean, info As String)
'--------------------------------
If success = True Then
ToastMessageShow("Phone number successfully verified!",True)
gb_phoneVerificationSuccess = True
Else
MsgboxAsync("Phone number verification failed!"& CRLF & "info: "& info, "Alert...")
gs_phoneNumber = ""
gs_signInMethod = ""
save_signInMethod
End If
End Sub