Android Question Owner accounts with all field

brelto85

Active Member
Licensed User
Longtime User
The first method return a owner account with some fields but there isn't a email
The second method list the accounts owner returns only a emails value

B4X:
Sub GetOwnerAccount() As Cursor
      Dim cr As ContentResolver
      Dim u As Uri
      u.Parse("content://com.android.contacts/profile")
      cr.Initialize("cr")
      Dim crsr As Cursor = cr.Query(u, Null, "", Null, "")
      crsr.Position = 0
      Return crsr
End Sub

Public Sub GetAccounts As List
    Dim r As Reflector
    Dim wAccounts As List
    wAccounts.Initialize
    r.Target = r.RunStaticMethod("android.accounts.AccountManager", "get", Array As Object(r.GetContext), Array As String("android.content.Context"))
    Dim accounts() As Object
    accounts = r.RunMethod2("getAccountsByType", "com.google", "java.lang.String")
    For i = 0 To accounts.Length - 1
          r.Target = accounts(i)
        wAccounts.Add(r.GetField ("name"))
      Next
    Return wAccounts
End Sub

How to merge?
I need to list the owner accounts recovering the email, name, surname and picture for each profile
 

Cableguy

Expert
Licensed User
Longtime User
Missed that one... since it was an edit it just passed me by, thanks again NJ
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Yes, I'm still fighting this one out!!!

My manifest is as shown:

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddPermission(android.permission.GET_ACCOUNTS)
AddPermission(android.permission.READ_CONTACTS)
 
'End of default text.

my Logs are:
B4X:
LogCat connected to: B4A-Bridge: arnova ARNOVA 101 G4-
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (service1) Create **
** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (CallSubDelayed - HeartBeat)
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/profile/raw_contacts from pid=3178, uid=10071 requires android.permission.READ_CONTACTS, or grantUriPermission()
    at android.os.Parcel.readException(Parcel.java:1425)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
    at android.content.ContentResolver.query(ContentResolver.java:372)
    at android.content.ContentResolver.query(ContentResolver.java:315)
    at anywheresoftware.b4a.objects.ContentResolverWrapper.Query(ContentResolverWrapper.java:43)
    at b4a.example.main._activity_create(main.java:315)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at b4a.example.main.afterFirstLayout(main.java:98)
    at b4a.example.main.access$100(main.java:16)
    at b4a.example.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
Connected to B4A-Bridge (Wifi)
running waiting messages (1)
** Activity (main) Resume **
Installing file.
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (CallSubDelayed - HeartBeat)
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/profile/raw_contacts from pid=3366, uid=10071 requires android.permission.READ_CONTACTS, or grantUriPermission()
    at android.os.Parcel.readException(Parcel.java:1425)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
    at android.content.ContentResolver.query(ContentResolver.java:372)
    at android.content.ContentResolver.query(ContentResolver.java:315)
    at anywheresoftware.b4a.objects.ContentResolverWrapper.Query(ContentResolverWrapper.java:43)
    at b4a.example.main._activity_create(main.java:315)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at b4a.example.main.afterFirstLayout(main.java:98)
    at b4a.example.main.access$100(main.java:16)
    at b4a.example.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
running waiting messages (1)
** Activity (main) Resume **
Installing file.
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (CallSubDelayed - HeartBeat)
sending message to waiting queue (CallSubDelayed - HeartBeat)
sending message to waiting queue (CallSubDelayed - HeartBeat)
sending message to waiting queue (CallSubDelayed - HeartBeat)
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/profile/raw_contacts from pid=3483, uid=10071 requires android.permission.READ_CONTACTS, or grantUriPermission()
    at android.os.Parcel.readException(Parcel.java:1425)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
    at android.content.ContentResolver.query(ContentResolver.java:372)
    at android.content.ContentResolver.query(ContentResolver.java:315)
    at anywheresoftware.b4a.objects.ContentResolverWrapper.Query(ContentResolverWrapper.java:43)
    at b4a.example.main._activity_create(main.java:315)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at b4a.example.main.afterFirstLayout(main.java:98)
    at b4a.example.main.access$100(main.java:16)
    at b4a.example.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
running waiting messages (4)
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
WakeLock already held.
Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (CallSubDelayed - HeartBeat)
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/profile/raw_contacts from pid=5210, uid=10071 requires android.permission.READ_CONTACTS, or grantUriPermission()
    at android.os.Parcel.readException(Parcel.java:1425)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
    at android.content.ContentResolver.query(ContentResolver.java:372)
    at android.content.ContentResolver.query(ContentResolver.java:315)
    at anywheresoftware.b4a.objects.ContentResolverWrapper.Query(ContentResolverWrapper.java:43)
    at b4a.example.main._activity_create(main.java:315)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at b4a.example.main.afterFirstLayout(main.java:98)
    at b4a.example.main.access$100(main.java:16)
    at b4a.example.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)

My test code is the example code unchanged and it just won't work!!!
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Maybe you have a hidden illegal character in the manifest (it happens sometimes when you copy-paste) better re-type the permissions, you should have these 3 for the example to work:
B4X:
AddPermission(android.permission.GET_ACCOUNTS)
AddPermission(android.permission.READ_CONTACTS)
AddPermission(android.permission.READ_PROFILE)
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
OK, I surrender!!!!

I just can't figure it out!!!
Here's my "project", can anyone please tell me whats wrong????
 

Attachments

  • TEST.zip
    6.3 KB · Views: 446
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
When I close the manifest it asks if I want to keep the changes, also when I selected or unselected the read only at rib for the manifest file it showed that it was only kept for backwards compatibility.
I will try again when I get home from work
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
When I close the manifest it asks if I want to keep the changes, also when I selected or unselected the read only at rib for the manifest file it showed that it was only kept for backwards compatibility.
I will try again when I get home from work
You should not set your manifest as read-only, and yes, that feature still exists for backwards compatibility, but since B4A introduced the Manifest Editor that feature was deprecated.
 
Upvote 0

brelto85

Active Member
Licensed User
Longtime User
yes, i read it
but since other applications (eg, play store) can retrieve this information (also on my phone) i think we can do
 
Upvote 0

brelto85

Active Member
Licensed User
Longtime User
probably KEY_USERDATA has the account's username
how to get it using this method?

B4X:
Public Sub GetAccounts As List
    Dim r As Reflector
    Dim wAccounts As List
    wAccounts.Initialize
    r.Target = r.RunStaticMethod("android.accounts.AccountManager", "get", Array As Object(r.GetContext), Array As String("android.content.Context"))
    Dim accounts() As Object
    accounts = r.RunMethod2("getAccountsByType", "com.google", "java.lang.String")
    For i = 0 To accounts.Length - 1
          r.Target = accounts(i)
        wAccounts.Add(r.GetField ("name"))
      Next
    Return wAccounts
End Sub
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Seems like you were right NJ, all works like a charm, thou its not logical to have and editor demanding if we want to keep the changes it they do not come to effect... but hey, maybe its me!!!
Don, Thanks for pointing up your permitions post, I had already been there!
 
Upvote 0

brelto85

Active Member
Licensed User
Longtime User
I've modify the method in this way (RunMethod3...)

B4X:
Public Sub GetAccounts As List
    Dim r As Reflector
    Dim wAccounts As List
    wAccounts.Initialize
    r.Target = r.RunStaticMethod("android.accounts.AccountManager", "get", Array As Object(r.GetContext), Array As String("android.content.Context"))
    Dim accounts() As Object
    accounts = r.RunMethod2("getAccountsByType", "com.google", "java.lang.String")
    Dim username As String
    For i = 0 To accounts.Length - 1
        username = r.RunMethod3("getUserData", accounts(i), "java.lang.Object", "KEY_USERDATA", "java.lang.String")
          r.Target = accounts(i)     
        wAccounts.Add(r.GetField ("name"))
      Next
    Return wAccounts
End Sub

but returns the follow error:
java.lang.NoSuchMethodException: getUserData [class java.lang.Object, class java.lang.String]

I've added also GET_ACCOUNTS and AUTHENTICATE_ACCOUNTS permission
how to do this?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the correct code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim am As JavaObject
   am = am.InitializeStatic("android.accounts.AccountManager").RunMethod("get", Array(GetContext))
   Dim accounts() As Object = am.RunMethod("getAccounts", Null)
   For Each account As Object In accounts
     Log(am.RunMethod("getUserData", Array(account, "userdata")))
   Next
End Sub

Sub GetContext As JavaObject
   Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
  Dim jo As JavaObject
  Dim cls As String = Me
  cls = cls.SubString("class ".Length)
  jo.InitializeStatic(cls)
  Return jo.GetFieldJO("processBA")
End Sub
However it will not work because of a security limitation: http://developer.android.com/refere...a(android.accounts.Account, java.lang.String)
 
Upvote 0

brelto85

Active Member
Licensed User
Longtime User
at Array(GetContext) and Array(account, "userdata"), i get an error during compile: 'as' expected
I've the 3.20 B4A version

I tried to modify like this: Array as Object(GetContext) and Array as object(account, "userdata") but when i run the application, returns this error:

java.lang.reflect.InvocationTargetException
...
..
..
..
Caused by: java.lang.SecurityException: caller uid 10023 is different than the authenticator's uid
 
Last edited:
Upvote 0

brelto85

Active Member
Licensed User
Longtime User
exactly
I decided to change the method and i'll use only getAccounts method that it always work

Exists a control like the attached to select the account?

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…