Open a layout for registration

0

I added my app to mobile accounts to be able to auto-login without the need to enter credentials. At the time of accessing the mobile section accounts I add my app, but it opens and closes as if I did not open the layout.

account_preference.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen 
 xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
    android:title="General Settings" />
<PreferenceScreen
    android:key="account_settings"
    android:title="Account Settings"
    android:summary="Sync frequency, notifications, etc." >
    <intent
        android:action="android.intent.action.VIEW"
        android:targetPackage="com.example.pargibay.androidphprpcxml"
        android:targetClass="com.example.pargibay.androidphprpcxml.AccountAuthenticatorSimpleActivity" />
</PreferenceScreen>

authenticator.xml

<?xml version="1.0" encoding="utf-8"?>
<account-authenticator 
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.example.pargibay.androidphprpcxml"
android:icon="@drawable/logoapp"
android:smallIcon="@drawable/logoapp"
android:label="@string/app_name"
android:accountPreferences="@xml/account_preference"
/>

AndroidManifest.xml

       <service
        android:name=".AccountAuthenticatorService"
        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>

In the class where I want you to register the accounts

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

    textuser = (TextView) findViewById(R.id.textUser);
    textpass = (TextView) findViewById(R.id.textPassword);
    txtuser = (EditText) findViewById(R.id.editTextUser);
    txtpass = (EditText) findViewById(R.id.editTextPass);

    username = txtuser.getText().toString().trim();
    password = txtpass.getText().toString().trim();

    accountManager = AccountManager.get(this);
    SharedPreferences settings = getSharedPreferences(PREFS, 0);
    //username = settings.getString("userName", "");

    if(username.equalsIgnoreCase("")){
        requestLogin();
    }else{
        Account[]accounts = accountManager.getAccountsByType(getResources().getString(R.string.account_type));
        if(accounts.length <= 0){
            requestLogin();
        }else{
            accountFound = false;
            for(Account account : accounts){
                if(account.name.equals(username)){
                    accountFound = true;
                    authToken = getAuthToken(account);
                    loginWithUserNameAuthToken(username, authToken);
                }
            }
            if(!accountFound){
                requestLogin();
            }
        }
    }


}

private void requestLogin(){
    Toast.makeText(this, "Algo ha ido mal, inicie sesión por favor", Toast.LENGTH_SHORT).show();
    setContentView(R.layout.activity_main);
}

private String getAuthToken(Account account) {
    return "";
}

private void loginWithUserNameAuthToken(String userName, String authToken) {
    Log.v(LOG_TAG, "Login with the user name \"" + userName + "\" and the authToken \"" + authToken);
}
}

And this is the Service class:

public class AccountAuthenticatorService extends Service {

private static final String LOG_TAG = AccountAuthenticatorService.class.getSimpleName();
private static AccountAuthenticatorImpl sAccountAuthenticator = null;

public AccountAuthenticatorService() {
    super();
}

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

public AbstractAccountAuthenticator getAuthenticator() {
    if (AccountAuthenticatorService.sAccountAuthenticator == null) {
        AccountAuthenticatorService.sAccountAuthenticator = new AccountAuthenticatorImpl(this);
    }
    return AccountAuthenticatorService.sAccountAuthenticator;
}

private static class AccountAuthenticatorImpl extends AbstractAccountAuthenticator {
    private Context mContext;

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

    @Override
    public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
        return null;
    }

    @Override
    public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
        Bundle reply = new Bundle();
        return reply;
    }

    @Override
    public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException {
        return null;
    }

    @Override
    public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
        return null;
    }

    @Override
    public String getAuthTokenLabel(String authTokenType) {
        return null;
    }

    @Override
    public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
        return null;
    }

    @Override
    public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException {
        return null;
    }

}
}

It seems to me that I have something wrong in the xml account_preference.xml or I'm missing. The idea that I have is when you want to add an account select my app and you get the window to add account and register it but that window does not come out.

    
asked by Pedro 04.05.2018 в 14:45
source

0 answers