3

I'm still having problems with the Method AccountManager.addAccountExplicitly. I want to create a App which is submitting a User PW combo to a website. The app should save the login data and therefore i wanted to use 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>

Everytime when executing the step

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

my app is stopping!!

some output of the console:

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

I hope you can help me

Thanks Michi

Mini Cascading
  • 83
  • 1
  • 2
  • 12
eismi
  • 111
  • 2
  • 9
  • I think this could be a duplicate of another question. Please see: http://stackoverflow.com/questions/13178022/addaccountexplicitly-throws-illegalstateexception-caused-by-securityexception – nibarius Feb 28 '13 at 20:04
  • Ok looks like the same problem but which userID is meant? I just added android:sharedUserId to my AndroidManifest.xml but i don't know which ID to deliver – eismi Mar 01 '13 at 07:35
  • You can use any userID that is unique to your apps (you could for example use "com.geberit.eisimi" or something similar). You just need to make sure you use the same id for both this app and the authenticator that handles the account you are trying to add. – nibarius Mar 03 '13 at 18:46
  • sorry but this didn't work! i have just added more code and the Android Manifest. Do i have to create an authenticator object??? – eismi Mar 04 '13 at 15:44
  • http://www.finalconcept.com.au/article/view/android-account-manager-step-by-step-1 http://www.finalconcept.com.au/article/view/android-account-manager-step-by-step-2 just tried this but it's a bit difficult – eismi Mar 05 '13 at 14:46
  • I haven't worked anything with custom accounts myself, but as I understand it you will have to create an authenticator object that authenticates the accounts you add. – nibarius Mar 05 '13 at 18:41
  • I'm using SharedPreferences now! I know it's not secure but it still works! Thank you for your effort! – eismi Mar 12 '13 at 06:39

0 Answers0