Accessing android Google Account Id /username via phonegap?
My suggestion would be to write the code for getting the Google Account info in Android Java like so:
http://developer.android.com/google/play-services/auth.html
And then create a JS interface to communicate with your webview to pass it the credentials like so:
https://stackoverflow.com/a/2737388/1062787
How to get android phone user's google account name?
try this
AccountManager manager = AccountManager.get(context);
Account[] accounts = manager.getAccountsByType("com.google");
List<String> username = new LinkedList<String>();
for (Account account : accounts) {
username.add(account.name);
}
and add permission to android manifest
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
How can I get the google username on Android?
As mentioned in the comments, Roman's answer to How to get the Android device's primary e-mail address solves it.
Here's the code i used that will also strip out the username from the email.
public String getUsername() {
AccountManager manager = AccountManager.get(this);
Account[] accounts = manager.getAccountsByType("com.google");
List<String> possibleEmails = new LinkedList<String>();
for (Account account : accounts) {
// TODO: Check possibleEmail against an email regex or treat
// account.name as an email address only for certain account.type values.
possibleEmails.add(account.name);
}
if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) {
String email = possibleEmails.get(0);
String[] parts = email.split("@");
if (parts.length > 1)
return parts[0];
}
return null;
}
How do I retrieve the logged in Google account on android phones?
Something like this should work:
AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
Account[] list = manager.getAccounts();
String gmail = null;
for(Account account: list)
{
if(account.type.equalsIgnoreCase("com.google"))
{
gmail = account.name;
break;
}
}
And you will need the following permission in your manifest:
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
Remember to 'Requesting Permissions at Run Time' if you support Android 6 and later
https://developer.android.com/training/permissions/requesting.html
I wrote this from memory so it may need a little tweaking. Apparently it's possible to register now without an email address, so maybe do some regexing on the data to ensure it's actually an email address (ensure it contains @gmail or @googlemail)
Related Topics
Tasksnapshot.Getdownloadurl() Is Deprecated
Failed to Find Target with Hash String 'Android-22'
Alertdialog.Getbutton() Method Gives Null Pointer Exception Android
Sqlite Exception No Such Column When Trying to Select
Android Detect Phone Lock Event
Place Imageview Over Button Android
How to Use the Gradle Build System for Android with Eclipse
Touch and Drag Image in Android
Android Listview Row Delete Animation
Android: Programmatically Adding Buttons to a Layout
Adding Your Own SQLite Database to an Android Application
Parse JSON Array Response Using Retrofit & Gson
Android Event for Internet Connectivity State Change
How to Change Toolbar Navigation and Overflow Menu Icons (Appcompat V7)