Android Question How to translate java (AccountPicker) to B4A ...

Discussion in 'Android Questions' started by Serway, Feb 23, 2018.

  1. Serway

    Serway Member Licensed User


    I'm trying to get user email registered account without the GET_ACCOUNTS permission (android.permission.GET_ACCOUNTS).

    Is anyone can help to translate into B4A (?) :

    public void pickUserAccount() {
        /*This will 
    list all available accounts on device without any filtering*/
    Intent intent = AccountPicker.newChooseAccountIntent(nullnullnullfalsenullnullnullnull);
     /*After manually selecting every app related account, I got its Account type using the code below*/
     @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE_PICK_ACCOUNT) {
            // Receiving a result from the AccountPicker
            if (resultCode == RESULT_OK) {
            } else if (resultCode == RESULT_CANCELED) {
                Toast.makeText(this, R.string.pick_account, Toast.LENGTH_LONG).show();
    Source :

  2. Erel

    Erel Administrator Staff Member Licensed User

    Sub ShowPicker
    Dim AccountPicker As JavaObject
    Dim i As Intent = AccountPicker.RunMethod("newChooseAccountIntent"Array(NullNullArray As String(""), _
    End Sub

    Sub ion_Event (MethodName As String, Args() As Object) As Object
    If Args(0) = -1 Then 'resultCode = RESULT_OK
           Dim data As Intent = Args(1)
    Dim StaticAccountManager As JavaObject
    Dim Name As String = data.GetExtra(StaticAccountManager.GetField("KEY_ACCOUNT_NAME"))
    End If
    Return Null
    End Sub

    Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
       ion = jo.CreateEvent(
    "startActivityForResult"Array As Object(ion, i))
    End Sub

    Sub GetBA As Object
    Dim jo As JavaObject
    Dim cls As String = Me
       cls = cls.SubString(
    "class ".Length)
    Return jo.GetField("processBA")
    End Sub
    Add google play services base manifest snippet:
    pesquera, Pencil3, Serway and 4 others like this.
  3. Serway

    Serway Member Licensed User

    Thank you Erel
  4. pesquera

    pesquera Active Member Licensed User


    I just need to read the first account.. I don´t need to pick from the accounts

    I have a routine into a class, called from different routines along the app
    Is it possible to adapt this code for my needs?

    Thanks in advance!
  5. DonManfred

    DonManfred Expert Licensed User

    I quoted a bit of the documentation in the other thread.
    If i remember correctly the quote states that you need to get the access one time using this method. After you got the permission you are allowed to use GET_ACCOUNT.
    Did i read that wrong?
  6. pesquera

    pesquera Active Member Licensed User

    Sorry for mix the threads, I thought that here was the solution I was looking for.. I will continue on the another thread.. excuse me for the inconvenience
  7. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    in Erel's code where is Ion defined and defined as what

    and when I execute the AccountsPicker.InitializeStatic I get

    Error occurred on line: 1656 (Main)
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(
    at anywheresoftware.b4j.object.JavaObject.InitializeStatic(
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(
    at anywheresoftware.b4a.BA$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invoke(Native Method)

    And I do have AdditionalJar statement
    Last edited: Jul 2, 2018
  8. Erel

    Erel Administrator Staff Member Licensed User

    Are you testing it on a real device?
  9. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    Yes. Samsung S7 just upgraded to Android 8.0
  10. Erel

    Erel Administrator Staff Member Licensed User

    Are you using B4A Sdk Manager?
  11. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    I am. But just made sure everything is up to date including tools and it seems to be working.

    Sorry should be better at keeping everything updated... But it is summer LOL
    Erel likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice