Skip to content

Commit 752b876

Browse files
author
Nilanchala
committed
Added code for getting all registered email accounts in Android
1 parent b197298 commit 752b876

File tree

22 files changed

+332
-0
lines changed

22 files changed

+332
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.javatechig.regemail"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="11"
9+
android:targetSdkVersion="17" />
10+
11+
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
12+
13+
<application
14+
android:allowBackup="true"
15+
android:icon="@drawable/ic_launcher"
16+
android:label="@string/app_name"
17+
android:theme="@style/AppTheme" >
18+
<activity
19+
android:name="com.javatechig.regemail.MainActivity"
20+
android:label="@string/app_name" >
21+
<intent-filter>
22+
<action android:name="android.intent.action.MAIN" />
23+
24+
<category android:name="android.intent.category.LAUNCHER" />
25+
</intent-filter>
26+
</activity>
27+
</application>
28+
29+
</manifest>
50.2 KB
Loading
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-17
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:id="@+id/listView1"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:layout_weight="1" >
7+
8+
</ListView>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="wrap_content"
5+
android:background="#C9DAF3"
6+
android:orientation="horizontal"
7+
android:padding="5dp"
8+
android:weightSum="2" >
9+
10+
<TextView
11+
android:id="@+id/key"
12+
android:layout_width="fill_parent"
13+
android:layout_height="wrap_content"
14+
android:layout_weight="1" />
15+
16+
<TextView
17+
android:id="@+id/value"
18+
android:layout_marginLeft="5dp"
19+
android:layout_width="fill_parent"
20+
android:layout_height="wrap_content"
21+
android:layout_weight="1" />
22+
23+
</LinearLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw600dp devices (e.g. 7" tablets) here.
6+
-->
7+
8+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
6+
-->
7+
<dimen name="activity_horizontal_margin">128dp</dimen>
8+
9+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 11+. This theme completely replaces
5+
AppBaseTheme from res/values/styles.xml on API 11+ devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
8+
<!-- API 11 theme customizations can go here. -->
9+
</style>
10+
11+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 14+. This theme completely replaces
5+
AppBaseTheme from BOTH res/values/styles.xml and
6+
res/values-v11/styles.xml on API 14+ devices.
7+
-->
8+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
9+
<!-- API 14 theme customizations can go here. -->
10+
</style>
11+
12+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<color name="blue">#00abea</color>
5+
<color name="white">#ffffff</color>
6+
7+
<color name="toast_bg_transparent">#E6000000</color>
8+
9+
10+
<color name="lovely_row_bg1">#D6DFEC</color>
11+
<color name="lovely_row_bg2">#fff</color>
12+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<resources>
2+
3+
<!-- Default screen margins, per the Android Design guidelines. -->
4+
<dimen name="activity_horizontal_margin">16dp</dimen>
5+
<dimen name="activity_vertical_margin">16dp</dimen>
6+
7+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="app_name">RegisteredEmailAccounts</string>
5+
6+
<string-array name="acounts_list">
7+
<item>All Accounts</item>
8+
<item>Google Accounts</item>
9+
</string-array>
10+
11+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme, dependent on API level. This theme is replaced
5+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Light">
8+
<!--
9+
Theme customizations available in newer API levels can go in
10+
res/values-vXX/styles.xml, while customizations related to
11+
backward-compatibility can go here.
12+
-->
13+
</style>
14+
15+
<!-- Application theme. -->
16+
<style name="AppTheme" parent="AppBaseTheme">
17+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
18+
</style>
19+
20+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.javatechig.regemail;
2+
3+
public class Item {
4+
5+
private String key;
6+
private String value;
7+
8+
public Item(String key, String value) {
9+
this.key = key;
10+
this.value = value;
11+
}
12+
13+
public String getKey() {
14+
return key;
15+
}
16+
17+
public void setKey(String key) {
18+
this.key = key;
19+
}
20+
21+
public String getValue() {
22+
return value;
23+
}
24+
25+
public void setValue(String value) {
26+
this.value = value;
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.javatechig.regemail;
2+
3+
import java.util.List;
4+
5+
import android.content.Context;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
import android.widget.ArrayAdapter;
10+
import android.widget.TextView;
11+
12+
public class LovelyListAdapter extends ArrayAdapter<Item> {
13+
private List<Item> appsList = null;
14+
private Context context;
15+
16+
public LovelyListAdapter(Context context, int textViewResourceId, List<Item> appsList) {
17+
super(context, textViewResourceId, appsList);
18+
this.context = context;
19+
this.appsList = appsList;
20+
}
21+
22+
@Override
23+
public int getCount() {
24+
return ((null != appsList) ? appsList.size() : 0);
25+
}
26+
27+
@Override
28+
public Item getItem(int position) {
29+
return ((null != appsList) ? appsList.get(position) : null);
30+
}
31+
32+
@Override
33+
public long getItemId(int position) {
34+
return position;
35+
}
36+
37+
@Override
38+
public View getView(int position, View convertView, ViewGroup parent) {
39+
View view = convertView;
40+
if (null == view) {
41+
LayoutInflater layoutInflater = (LayoutInflater) context
42+
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
43+
view = layoutInflater.inflate(R.layout.lovely_view_layout, null);
44+
}
45+
46+
if (position % 2 == 1) {
47+
view.setBackgroundColor(context.getResources().getColor(R.color.lovely_row_bg1));
48+
} else {
49+
view.setBackgroundColor(context.getResources().getColor(R.color.lovely_row_bg2));
50+
}
51+
52+
53+
Item data = appsList.get(position);
54+
if (null != data) {
55+
56+
TextView appName = (TextView) view.findViewById(R.id.key);
57+
TextView packageName = (TextView) view.findViewById(R.id.value);
58+
59+
appName.setText(data.getKey());
60+
packageName.setText(data.getValue());
61+
}
62+
return view;
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)