|
| 1 | +package com.javatechig.regemail; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | + |
| 5 | +import android.accounts.Account; |
| 6 | +import android.accounts.AccountManager; |
| 7 | +import android.app.Activity; |
| 8 | +import android.os.Bundle; |
| 9 | +import android.util.Log; |
| 10 | +import android.widget.ListView; |
| 11 | + |
| 12 | +public class MainActivity extends Activity { |
| 13 | + |
| 14 | + private ArrayList<Item> list = null; |
| 15 | + private ListView listView; |
| 16 | + private LovelyListAdapter listadaptor; |
| 17 | + |
| 18 | + @Override |
| 19 | + protected void onCreate(Bundle savedInstanceState) { |
| 20 | + super.onCreate(savedInstanceState); |
| 21 | + setContentView(R.layout.activity_main); |
| 22 | + |
| 23 | + list = getData(); |
| 24 | + listView = (ListView) findViewById(R.id.listView1); |
| 25 | + listadaptor = new LovelyListAdapter(this, R.layout.lovely_view_layout, list); |
| 26 | + listView.setAdapter(listadaptor); |
| 27 | + } |
| 28 | + |
| 29 | + private ArrayList<Item> getData() { |
| 30 | + ArrayList<Item> accountsList = new ArrayList<Item>(); |
| 31 | + |
| 32 | + //Getting all registered Google Accounts; |
| 33 | + try { |
| 34 | + Account[] accounts = AccountManager.get(this).getAccountsByType("com.google"); |
| 35 | + for (Account account : accounts) { |
| 36 | + Item item = new Item( account.type, account.name); |
| 37 | + accountsList.add(item); |
| 38 | + } |
| 39 | + } catch (Exception e) { |
| 40 | + Log.i("Exception", "Exception:" + e); |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + //For all registered accounts; |
| 45 | + /*try { |
| 46 | + Account[] accounts = AccountManager.get(this).getAccounts(); |
| 47 | + for (Account account : accounts) { |
| 48 | + Item item = new Item( account.type, account.name); |
| 49 | + accountsList.add(item); |
| 50 | + } |
| 51 | + } catch (Exception e) { |
| 52 | + Log.i("Exception", "Exception:" + e); |
| 53 | + }*/ |
| 54 | + return accountsList; |
| 55 | + } |
| 56 | +} |
0 commit comments