3

我有以下帐户身份验证类

public class AppAuthenticator extends AbstractAccountAuthenticator {

private Context mContext;

public AppAuthenticator(Context context) {
    super(context);
    mContext = context;
}

//This is used by the login activity when the guy logs in after starting the app
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, 
        String[] requiredFeatures, Bundle options)
        throws NetworkErrorException {
        //...Code Here...
    }

}

public class AuthenticationService extends Service {

private static AppAuthenticator sAuthenticator = null;

public AuthenticationService() {
    super();
}

@Override
public IBinder onBind(Intent intent) {
    IBinder res = null;
    if (intent.getAction().equals(android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT))
        res = getAuthenticator().getIBinder();
    return res;
}

private AppAuthenticator getAuthenticator() {
    if (sAuthenticator == null)
        sAuthenticator = new AppAuthenticator(this);
    return sAuthenticator;
}
}

和清单:xml/authenticator.xml

<account-authenticator 
    xmlns:android="http://schems.android.com/apk/res/android"
    android:accountType="@string/account_type" 
    android:label="@string/app_name" 
    android:icon="@drawable/benchcap" />

androidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.app"
    android:versionCode="1"
    android:versionName="1.0" >

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

<application
    android:name="com.app.app.AppApplication"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <service android:name=".AuthenticationService"
        android:exported="true" android:process=":auth">
        <intent-filter>
            <action android:name="android.accounts.AccountAuthenticator" />
        </intent-filter>

        <meta-data
            android:name="android.accounts.AccountAuthenticator"
            android:resource="@xml/authenticator" />
    </service>
</application>

@string/app_name="App"和_@string/account_type="com.app.app"

所以问题是安装应用程序时我得到

"Unable to load service info ResolveInfo{40f00c40 com.app.app.AuthenticationService p=0 m=0x108000}
 Loaded meta-data for 0 account types, 0 accounts in 4ms(wall) 2ms(cpu)"

并且我尝试添加帐户我得到 SecurityException "Caller UID is different than the authenticationator UID" (这里描述:SecurityException: caller uid XXXX is different than the authenticationator's uid)。这是有道理的,因为该服务未注册。

系统提供的信息仅此而已。

需要添加什么才能正确注册身份验证服务?

4

0 回答 0