2014-11-20 7 views
1

답변이나 끊어진 외부 링크없이이 주제에 대한 많은 질문을 발견했습니다. 간단한 방법으로 계정을 추가하고 싶습니다. 오류는 항상 동일합니다 : java.lang.SecurityException : 호출자 uid xxxxx는 인증 자의 uid (addAccountExplicitly를 호출하는 곳)와 다릅니다. 하지만 계정 유형은 코드와 XML에서 동일하므로 ... 내가 잘못하고있는 곳은 어디입니까?어떻게 AddAccountExplicitly 계정을 추가 할 수 있습니까?

public class AuthActivity extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_auth); 

     AccountManager accountManager = AccountManager.get(this); 
     final Account account = new Account("username", getString(R.string.account_type)); 
     accountManager.addAccountExplicitly(account, "password", null); 
    } 
} 

<?xml version="1.0" encoding="utf-8"?> 
<account-authenticator 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:accountType="@string/account_type" 
    android:icon="@drawable/ic_launcher" 
    android:smallIcon="@drawable/ic_launcher" 
    android:label="@string/name_app" /> 
+0

Google, Facebook 또는 이와 유사한 계정이 아닌 자신의 계정 유형을 추가하려고합니다. – nibarius

+2

예, 당연히 맞춤 계정 유형을 추가하려고합니다. –

답변

0

예외적으로 응용 프로그램과 인증 기가 동일한 UID를 공유해야합니다. 일반적으로 모든 다른 응용 프로그램은 다른 UID를 가지므로 UID를 공유하도록 특별히 설정하지 않은 경우 다른 UID를 갖습니다.

ApplicationInfo.uid을 통해 앱이 할당 된 UID를 확인할 수 있습니다. getApplicationInfo()PackageManager에 사용하여 ApplicationInfo를 확보 할 수 있습니다.

인증 자와 앱 모두에 대한 매니페스트 파일의 android:sharedUserId 속성을 사용하여 공유 UID를 설정할 수 있습니다.

1

나는 당신과 같은 문제가있었습니다.

<service 
     android:name="com.example.android.syncadapter.AuthenticatorService"> 
    <intent-filter> 
     <action android:name="android.accounts.AccountAuthenticator"/> 
    </intent-filter> 
    <meta-data 
     android:name="android.accounts.AccountAuthenticator" 
     android:resource="@xml/authenticator" /> 
</service> 

귀하의 텐트 필터 이름은 안드로이드 프레임 워크에 의해 정의된다 : 내가 제대로 내 응용 프로그램에서 매니페스트 파일을 내 인증 서비스를 등록하지 않은 것으로 밝혀졌다. 따라서 "android.accounts.AccountAuthenticator"가되어야합니다