Selasa, 28 Juli 2020

GET ACCOUNT MAIL

package com.example.registeredemails;

import android.os.Bundle;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.util.Log;
import android.widget.TextView;

public class RegisteredEmailAccounts extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.registered_email_account);
final TextView accountsData = (TextView) findViewById(R.id.accounts);

String possibleEmail="";

   try{
       possibleEmail += "************* Get Registered Gmail Account *************\n\n";
       Account[] accounts = AccountManager.get(this).getAccountsByType("com.google");
     
       for (Account account : accounts) {
       
    possibleEmail += " --> "+account.name+" : "+account.type+" , \n";
         possibleEmail += " \n\n";
       
       }
  }
      catch(Exception e)
      {
       Log.i("Exception", "Exception:"+e) ;
      }
     
     
      try{
       possibleEmail += "**************** Get All Registered Accounts *****************\n\n";
     
       Account[] accounts = AccountManager.get(this).getAccounts();
       for (Account account : accounts) {
       
      possibleEmail += " --> "+account.name+" : "+account.type+" , \n";
          possibleEmail += " \n";
       
       }
  }
      catch(Exception e)
      {
       Log.i("Exception", "Exception:"+e) ;
      }
 
   // Show on screen   
   accountsData.setText(possibleEmail);
     
       Log.i("Exception", "mails:"+possibleEmail) ;
}


}
++++++++++++++++
<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"
    tools:context=".RegisteredEmailAccounts" >

    <TextView
        android:id="@+id/accounts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

</RelativeLayout>


++++++++++++++++++++


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

Tidak ada komentar:

Posting Komentar