Determination of the mail address of the device

Status
Not open for further replies.

Amalkotey

Active Member
Licensed User
Hallo,

gibt es eine Möglichkeit, die EMail-Adresse, welche im Device gespeichert ist, abzufragen? Vielen Dank für euere Hilfe im Voraus.

Mit freundlichen Grüssen

Amalkotey

-------------------------------------

Hello,

is there a way, the e - mail address which is stored in the device to query? Thank you for your help in advance.

best regards

Amalkotey
 

Amalkotey

Active Member
Licensed User
@Erel:

thank you for the information. Ih have now tested again. with the following java code I get a NullPointerException.

B4X:
mAccountManager = AccountManager.get(mContext.getApplicationContext()); // NullPointerException
Account[] accounts = mAccountManager.getAccountsByType("com.google");
String myEMailId = accounts[0].toString();

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?
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
Here is the code with reflection:
B4X:
   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
 
Upvote 0

Amalkotey

Active Member
Licensed User
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
 

Attachments

  • java.lang.SecurityException.jpg
    java.lang.SecurityException.jpg
    10.9 KB · Views: 423
  • Reflector-Demo GetMailAccounts.zip
    6.1 KB · Views: 453
Last edited:
Upvote 0

Amalkotey

Active Member
Licensed User
Works fine!

@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.

B4X:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

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.

B4X:
accounts = r.RunMethod("getAccounts")

regards
Amalkotey
 
Last edited:
Upvote 0

appie21

Active Member
Licensed User
Hello

i try to add this line to my Manifest but give a error
B4X:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

How to add correct to the manifest?
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
B4X:
AddManifestText(<uses-permission android:name="android.permission.GET_ACCOUNTS" />)

Sergio
 
Upvote 0

Derek Johnson

Active Member
Licensed User
The code above works fine, but I see that there is a way in Android to get a list of accounts with an intent.

Here is a link to the facility

http://developer.android.com/reference/com/google/android/gms/common/AccountPicker.html

Extract:

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.
 
Upvote 0

Alisson

Active Member
Licensed User
Erel

I try use the code:

B4X:
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

I add
B4X:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

And
B4X:
<uses-permission android:name="android.permission.LOGIN_ACCOUNTS_CHANGED_ACTION" />

I look the link: http://developer.android.com/refere...tml#getPreviousName(android.accounts.Account)

But I cant determine the name of the device. Just e-mail.

You can help me?

Thanks!
 
Upvote 0

Derek Johnson

Active Member
Licensed User
What do you mean by "The name of the device", are you looking for the Android Device ID, or perhaps the Android User ID?

Both of these are easy to find, also you can get the primary email address, at least the first one that was used on the device.

Derek
 
Upvote 0

Alisson

Active Member
Licensed User
Derek,

I want the user name email.
In the Name field , I suggest the name of the email.
If you do not want that name suggested in field may change.

Example:

I have the interface of register.

My e-mail is: alisson2016@gmail.com

In field e-mail show the e-mail "alisson2016@gmail.com"
and
in field name show the owner name "Alisson".

thanks to answer!
 
Last edited:
Upvote 0

Alisson

Active Member
Licensed User
Erel.

I try your example, but have error, look:
B4X:
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".
 
Upvote 0
Status
Not open for further replies.
Top