Skip to content

Commit 6ea13fe

Browse files
committed
added account manager example.
1 parent 032bdea commit 6ea13fe

File tree

14 files changed

+294
-0
lines changed

14 files changed

+294
-0
lines changed

account-manager-example/.classpath

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry kind="output" path="bin/classes"/>
8+
</classpath>

account-manager-example/.project

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>AccountManagerExample</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="net.yuki24.examples.AccountManager" android:versionCode="1" android:versionName="1.0">
4+
5+
<uses-sdk android:minSdkVersion="10" />
6+
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
7+
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
8+
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
9+
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
10+
<uses-permission android:name="android.permission.INTERNET" />
11+
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
12+
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
13+
<uses-permission android:name="android.permission.READ_CONTACTS" />
14+
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
15+
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
16+
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
17+
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
18+
<uses-permission android:name="android.permission.READ_SOCIAL_STREAM" />
19+
<uses-permission android:name="android.permission.WRITE_SOCIAL_STREAM" />
20+
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
21+
<activity android:name=".AccountManagerExampleActivity" android:label="@string/app_name">
22+
<intent-filter>
23+
<action android:name="android.intent.action.MAIN" />
24+
<category android:name="android.intent.category.LAUNCHER" />
25+
</intent-filter>
26+
</activity>
27+
<service android:name=".core.ExampleAuthenticatationService">
28+
<intent-filter>
29+
<action android:name="android.accounts.AccountAuthenticator"></action>
30+
</intent-filter>
31+
<meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator" />
32+
</service>
33+
</application>
34+
</manifest>

account-manager-example/proguard.cfg

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-optimizationpasses 5
2+
-dontusemixedcaseclassnames
3+
-dontskipnonpubliclibraryclasses
4+
-dontpreverify
5+
-verbose
6+
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7+
8+
-keep public class * extends android.app.Activity
9+
-keep public class * extends android.app.Application
10+
-keep public class * extends android.app.Service
11+
-keep public class * extends android.content.BroadcastReceiver
12+
-keep public class * extends android.content.ContentProvider
13+
-keep public class * extends android.app.backup.BackupAgentHelper
14+
-keep public class * extends android.preference.Preference
15+
-keep public class com.android.vending.licensing.ILicensingService
16+
17+
-keepclasseswithmembernames class * {
18+
native <methods>;
19+
}
20+
21+
-keepclasseswithmembers class * {
22+
public <init>(android.content.Context, android.util.AttributeSet);
23+
}
24+
25+
-keepclasseswithmembers class * {
26+
public <init>(android.content.Context, android.util.AttributeSet, int);
27+
}
28+
29+
-keepclassmembers class * extends android.app.Activity {
30+
public void *(android.view.View);
31+
}
32+
33+
-keepclassmembers enum * {
34+
public static **[] values();
35+
public static ** valueOf(java.lang.String);
36+
}
37+
38+
-keep class * implements android.os.Parcelable {
39+
public static final android.os.Parcelable$Creator *;
40+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 use,
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
10+
# Project target.
11+
target=android-10
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
5+
android:orientation="vertical" >
6+
7+
<TextView
8+
android:layout_width="fill_parent"
9+
android:layout_height="wrap_content"
10+
android:text="@string/hello" />
11+
12+
</LinearLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="hello">Hello World, AccountManagerExampleActivity!</string>
5+
<string name="app_name">AccountManagerExample</string>
6+
7+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:accountType="net.yuki24.examples"
3+
android:icon="@drawable/ic_launcher"
4+
android:label="@string/app_name"
5+
android:smallIcon="@drawable/ic_launcher" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package net.yuki24.examples.AccountManager;
2+
3+
import java.util.ArrayList;
4+
5+
import net.yuki24.examples.AccountManager.authenticator.ExampleAccountAuthenticator;
6+
7+
import android.accounts.Account;
8+
import android.accounts.AccountAuthenticatorActivity;
9+
import android.accounts.AccountManager;
10+
import android.app.Activity;
11+
import android.content.Intent;
12+
import android.os.Bundle;
13+
import android.provider.SyncStateContract.Constants;
14+
15+
public class AccountManagerExampleActivity extends AccountAuthenticatorActivity {
16+
@Override
17+
public void onCreate(Bundle savedInstanceState) {
18+
super.onCreate(savedInstanceState);
19+
setContentView(R.layout.main);
20+
21+
ArrayList<String> accountsInfo = new ArrayList<String>();
22+
AccountManager manager = AccountManager.get(this);
23+
Account[] accounts = manager.getAccounts();
24+
for (Account account : accounts) {
25+
String name = account.name;
26+
String type = account.type;
27+
int describeContents = account.describeContents();
28+
int hashCode = account.hashCode();
29+
30+
accountsInfo.add("name = " + name +
31+
"\ntype = " + type +
32+
"\ndescribeContents = " + describeContents +
33+
"\nhashCode = " + hashCode);
34+
}
35+
String[] result = new String[accountsInfo.size()];
36+
accountsInfo.toArray(result);
37+
38+
String username = "hoge";
39+
String password = "fuga";
40+
String accountType = "net.yuki24.examples";
41+
42+
// This is the magic that addes the account to the Android Account Manager
43+
final Account account = new Account(username, accountType);
44+
manager.addAccountExplicitly(account, password, null);
45+
46+
// Now we tell our caller, could be the Andreid Account Manager or even our own application
47+
// that the process was successful
48+
final Intent intent = new Intent();
49+
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, username);
50+
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
51+
intent.putExtra(AccountManager.KEY_AUTHTOKEN, accountType);
52+
this.setAccountAuthenticatorResult(intent.getExtras());
53+
this.setResult(RESULT_OK, intent);
54+
this.finish();
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package net.yuki24.examples.AccountManager.authenticator;
2+
3+
import net.yuki24.examples.AccountManager.AccountManagerExampleActivity;
4+
import android.accounts.AbstractAccountAuthenticator;
5+
import android.accounts.Account;
6+
import android.accounts.AccountAuthenticatorResponse;
7+
import android.accounts.AccountManager;
8+
import android.accounts.NetworkErrorException;
9+
import android.content.Context;
10+
import android.content.Intent;
11+
import android.os.Bundle;
12+
import android.provider.SyncStateContract.Constants;
13+
14+
public class ExampleAccountAuthenticator extends AbstractAccountAuthenticator {
15+
private Context mContext;
16+
17+
public ExampleAccountAuthenticator(Context context) {
18+
super(context);
19+
mContext = context;
20+
// TODO Auto-generated constructor stub
21+
}
22+
23+
@Override
24+
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options)
25+
throws NetworkErrorException {
26+
final Bundle result;
27+
final Intent intent;
28+
29+
intent = new Intent(this.mContext, AccountManagerExampleActivity.class);
30+
intent.putExtra(Constants.ACCOUNT_TYPE, authTokenType);
31+
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
32+
33+
result = new Bundle();
34+
result.putParcelable(AccountManager.KEY_INTENT, intent);
35+
36+
return result;
37+
}
38+
39+
@Override
40+
public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException {
41+
// TODO Auto-generated method stub
42+
return null;
43+
}
44+
45+
@Override
46+
public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
47+
// TODO Auto-generated method stub
48+
return null;
49+
}
50+
51+
@Override
52+
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
53+
// TODO Auto-generated method stub
54+
return null;
55+
}
56+
57+
@Override
58+
public String getAuthTokenLabel(String authTokenType) {
59+
// TODO Auto-generated method stub
60+
return null;
61+
}
62+
63+
@Override
64+
public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException {
65+
// TODO Auto-generated method stub
66+
return null;
67+
}
68+
69+
@Override
70+
public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
71+
// TODO Auto-generated method stub
72+
return null;
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package net.yuki24.examples.AccountManager.core;
2+
3+
import net.yuki24.examples.AccountManager.authenticator.ExampleAccountAuthenticator;
4+
import android.app.Service;
5+
import android.content.Intent;
6+
import android.os.IBinder;
7+
8+
public class ExampleAuthenticationService extends Service {
9+
@Override
10+
public IBinder onBind(Intent intent) {
11+
// TODO Auto-generated method stub
12+
return new ExampleAccountAuthenticator(this).getIBinder();
13+
}
14+
}

0 commit comments

Comments
 (0)