When trying to add a new Account to android 2.3.6 using the method :
AccountManager am = AccountManager.get(this);
boolean accountCreated = am.addAccountExplicitly(account,
password, null);
There is a service that should authenticate :
public class AccountAuthenticatorService extends Service {
private AccountAuthenticator mAccountAuthenticator;
@Override
public void onCreate() {
mAccountAuthenticator = new AccountAuthenticator(this);
}
@Override
public IBinder onBind(Intent intent) {
return mAccountAuthenticator.getIBinder();
}
}
And ofcourse:
public class AccountAuthenticator extends AbstractAccountAuthenticator
{
public static final String ACCOUNT_NAME =
"[email protected]";
public static final String ACCOUNT_TYPE = "com.google";
private Context mContext;
private AccountManager mAccountManager;
public AccountAuthenticator(Context context) {
super(context);
mContext = context;
mAccountManager = AccountManager.get(context);
}
@Override
public Bundle addAccount(AccountAuthenticatorResponse response,
String accountType,
String authTokenType, String[] requiredFeatures,
Bundle options) throws NetworkErrorException {
Bundle reply = new Bundle();
Intent i = new Intent(mContext, LoginActivity.class);//
Explicit intent to start LoginActivity/
i.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,
response);
reply.putParcelable(AccountManager.KEY_INTENT, i);
return reply;
}
@Override
public Bundle confirmCredentials(AccountAuthenticatorResponse arg0,
Account arg1, Bundle arg2) throws NetworkErrorException {
// TODO Auto-generated method stub
return null;
}
@Override
public Bundle editProperties(AccountAuthenticatorResponse arg0, String
arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse arg0, Account
arg1,
String arg2, Bundle arg3) throws NetworkErrorException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getAuthTokenLabel(String arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public Bundle hasFeatures(AccountAuthenticatorResponse arg0, Account
arg1,
String[] arg2) throws NetworkErrorException {
// TODO Auto-generated method stub
return null;
}
@Override
public Bundle updateCredentials(AccountAuthenticatorResponse arg0,
Account arg1, String arg2, Bundle arg3) throws
NetworkErrorException
{
// TODO Auto-generated method stub
return null;
}
}
The Manifest looks like that :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.com.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission
android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".Test_Activity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity"
android:label="this is the label"
android:theme="@android:style/Theme.Dialog"
android:excludeFromRecents="true" />
<service
android:name=".authenticator.AccountAuthenticatorService"
android:exported="true">
<intent-filter>
<action
android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
</application>
</manifest>
authenticator.xml looks like that:
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/
res/android"
android:accountType="com.google"
android:icon="@drawable/ic_launcher"
android:smallIcon="@drawable/ic_launcher"
android:label="@string/hello"
/>
I looked everywhere and I can't find a solution to this. I tried many
solutions people posted over the net and nothing works. Please help I
really need your assistance. Thank You!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en