Click Here To Download Apk File
activity_my.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity"
android:id="@+id/hello"
android:background="#00FFBB"
>
<Button
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="Click Here TO View Email"
android:id="@+id/find"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="102dp" />
</RelativeLayout>
AndroidManifest.xml
Take Permission
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
Activity_my.Java
package com.example.abdullah.find_email;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Patterns;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.util.regex.Pattern;
public class MyActivity extends ActionBarActivity {
Button Find;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
Find = (Button) findViewById(R.id.find);
final Context context = this;
Find.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
Account[] accounts = AccountManager.get(context).getAccounts();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
String possibleEmail = account.name;
Toast.makeText(getApplicationContext(), possibleEmail,Toast.LENGTH_LONG).show();
}
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Sorry Not Administrator Problem", Toast.LENGTH_LONG).show();
}
}
});
}
}