It shouldn't be difficult to do with the reflection library, based on this solution: How to get the Android device's primary e-mail address - Stack Overflow
Note that it requires the following permission: android.permission.GET_ACCOUNTS
If you need I can help you write the required Reflection code.
I can not get a reference from "mContext.getApplicationContext()". When I refer to the instance with this, the get method as shown in the Eclipse error. How can I come to the application context?
Dim r As Reflector
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)
Dim accountName As String
accountName = r.GetField("name")
Log(accountName)
Next
Runtime-Exception on Device: "java.lang.SecurityException"
@Erel:
Thank you for the code. Unfortunately, I get a "java.lang.SecurityException". Can you please check what's the error? The demo project is included in the zip. Thanks in advance.
Custom-ROM: DeFroST v6.01.a_esdaSO_v1.01.03 for HTC Desire Classic (AOSP FR83 + CyanogenMod)
Android-Vers: FroJo v 2.2.1 with Kernel: 2.6.35.7-defrost-bravotrip@trip-laptop #453
@agraham:
Thanks for the tip. I had entered the requirement of permission in the AndroidManifest and save the XML file. Unfortunately I had left open the XML Notepad and just went shopping for the weekend. When I got home, the XML editor was closed. What had happened? My little son, 5 years young, had watched what I 'm doing - could even be a game - and the entry has accidentally "uses-permission" is deleted and then also stored.
I 've corrected it in AndroidManifest and it now works correctly. The demo in the forum I have updated and uploaded. How would the code be changed if I want to retrieve all e-mail accounts, which the same provider? With the code below I only get the accounts of google.
Returns an intent to an Activity that prompts the user to choose from a list of accounts. The caller will then typically start the activity by calling startActivityForResult(intent, ...);.
Could anyone clarify whether this will still need exactly the same android.permission.GET_ACCOUNTS? If not some code to do this using the reflection library would be really useful.
Dim r As Reflector
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("getPreviousName","com.google", "java.lang.String")
For i = 0 To accounts.Length - 1
r.Target = accounts(i)
Dim accountName As String
accountName = r.GetField("name")
Log(accountName)
Next
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Installing file.
PackageAdded: package:b4a.example
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 333)
java.lang.IllegalArgumentException: URI: content://com.android.contacts/profile/raw_contacts, calling user: b4a.example, calling package:b4a.example
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:144)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
at android.content.ContentResolver.query(ContentResolver.java:262)
at anywheresoftware.b4a.objects.ContentResolverWrapper.Query(ContentResolverWrapper.java:43)
at b4a.example.main._activity_create(main.java:333)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
What am I doing wrong?
Thanks for the tip of the: "Owner accounts with all field".