Get Registered Email From Android Device
We just need to get account fron Account Manager. Here is the code...
MainActivity.java
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.os.Bundle;
import android.util.Patterns;
public class MainActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
Account[] accounts = AccountManager.get(this).getAccounts();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
String possibleEmail = account.name;
System.out.println("Here is email address in matches........[" + possibleEmail + "]");
}
System.out.println("Here is email address........[" + account.name + "]" + "{" + account.type +"}");
}
}
We also require user permintion:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
You can download source code from here.
Reference: Googling
No comments:
Post a Comment