Android Question WebView - How Remember the credentials of a site?

WebQuest

Active Member
Licensed User
Hi I was wondering how to set up a webview to remember the login credentials of the google account? I heard that you have to set cookies someone might want to give you an example.
 

sfsameer

Expert
Licensed User
Hi I was wondering how to set up a webview to remember the login credentials of the google account? I heard that you have to set cookies someone might want to give you an example.
Hello,

I think you need the following library to accept cookies in a webview :

Thank you,
Saif
 
Upvote 0

WebQuest

Active Member
Licensed User
Thanks for the quick response. However, I don't understand how I can remember the credentials. This is the example in the library. how do i set cookies to store credentials?

Code:
'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim CookieManager1 As CookieManager
    Dim WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    WebView1.Initialize("WebView1")
    Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
    '    call SetAcceptCookie after WebView has been initialized
    CookieManager1.SetAcceptCookies(True)
    
    '    load a webpage that requires a login
    Dim Url As String
    Url="https://accounts.google.com/signin/v2/identifier?service=CPanel&flowName=GlifWebSignIn&flowEntry=ServiceLogin"    '    change this to your login page
    WebView1.LoadUrl(Url)
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebView1_PageFinished (Url As String)
    Log("WebView1_PageFinished Url = "&Url)
    If CookieManager1.HasCookies Then
        Log("Cookies: "&CookieManager1.GetCookie(Url))
    Else
        Log("No cookies found")
    End If
End Sub
 
Upvote 0

sfsameer

Expert
Licensed User
Hello Dear,

Just used the example provided in the library :
B4A:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: CookieManager Example
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim CookieManager1 As CookieManager
    Dim WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    WebView1.Initialize("WebView1")
    Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
    '    call SetAcceptCookie after WebView has been initialized
    CookieManager1.SetAcceptCookies(True)
    
    '    load a webpage that requires a login
    Dim Url As String
    Url="http://b4xcode.com"    '    change this to your login page
    WebView1.LoadUrl(Url)
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebView1_PageFinished (Url As String)
    Log("WebView1_PageFinished Url = "&Url)
    If CookieManager1.HasCookies Then
        Log("Cookies: "&CookieManager1.GetCookie(Url))
    Else
        Log("No cookies found")
    End If
End Sub

And logged in to my website then closed the app then opened it again and the login session was saved in the browser:

1626694979739.png



Thank you,
Saif
 
Upvote 0

WebQuest

Active Member
Licensed User
I'm trying the same thing but with the google account it doesn't work. The code is the same, what am I doing wrong?
 
Upvote 0
Top