Android Question Find accounts in the device

PoleStar

Member
Licensed User
Longtime User
Hi any one
I was to find and add a accounts in the device.
Sample: Google , IAMP , Telegram , ect
How can?
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
From here http://stackoverflow.com/questions/...ccounts-facebook-twitter-gmail-etc-in-android

B4X:
    Dim AccountManager As JavaObject
   
    AccountManager.InitializeContext
   
    Log(AccountManager.RunMethod("getAccounts",Null))
   
   

#If JAVA

import android.accounts.AccountManager;
import android.accounts.Account;
import java.util.List;
import java.util.ArrayList;
import     java.util.Arrays;
import java.lang.Object;
public anywheresoftware.b4a.objects.collections.List getAccounts () {



    AccountManager am = AccountManager.get(this);
    Account [] acc = am.getAccounts();

   
    anywheresoftware.b4a.objects.collections.List l1 = new anywheresoftware.b4a.objects.collections.List();
        List listy = new ArrayList<Object>();
        listy=Arrays.asList(acc);
        l1.setObject(listy);
    return l1;
   
}
#End if

You need to add "android.permission.GET_ACCOUNTS" permission to your manifest .

for some reason I couldn't iterate through the accounts list

Someone might tell us why
I get "java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.List cannot be cast to java.util.List"
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
you need to create a anywheresoftware.b4a.objects.collections.List and give this list back to the app in the return statement.
The list you defined is a java.util.List but B4A is expecting anywheresoftware.b4a.objects.collections.List
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
you need to create a anywheresoftware.b4a.objects.collections.List and give this list back to the app in the return statement.
The list you defined is a java.util.List but B4A is expecting anywheresoftware.b4a.objects.collections.List
I am returning anywheresoftware.b4a.objects.collections.List .
It is the same way I use in libraries .
B4X:
 anywheresoftware.b4a.objects.collections.List l1 = new anywheresoftware.b4a.objects.collections.List();
        List listy = new ArrayList<Object>();
        listy=Arrays.asList(acc);
        l1.setObject(listy);
    return l1;
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…