Android AccountManager.addAccount明显停止我的应用程序

时间:2013-02-28 15:46:38

标签: android account accountmanager

我仍然遇到方法AccountManager.addAccountExplicitly的问题。 我想创建一个向网站提交用户PW组合的应用程序。 应用程序应保存登录数据,因此我想使用AccountManager:

HttpAuth.java:

package com.geberit.eismi.httpauth;

import android.os.Bundle;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.HttpAuthHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.Button;

public class HttpAuth extends Activity {

 private EditText field_username;
 private EditText field_password;
 private Button btn_login;
 private AccountManager accountM;
 private Account eismi;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    accountM = AccountManager.get(this);
    eismi = new Account("eismi", "com.geberit.sap.t81");

    boolean test = accountM.addAccountExplicitly(eismi, "testpassword", null);

    field_username = (EditText) findViewById(R.id.field_user);
    field_password = (EditText) findViewById(R.id.field_password);
    btn_login = (Button) findViewById(R.id.btn_login);

    field_username.setText(accountM.getPassword(eismi));

HttpAuth Manifest:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.geberit.eismi.httpauth.HttpAuth"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

每次执行步骤

boolean test = accountM.addAccountExplicitly(eismi, "testpassword", null); 

我的应用正在停止!!

控制台的某些输出:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.geberit.eismi.httpauth/com.geberit.eismi.httpauth.HttpAuth}: java.lang.SecurityException: caller uid 10039 is different than the authenticator's uid

我希望你能帮助我

谢谢Michi

0 个答案:

没有答案