Why Login not working on Authorize.net on android
<p>I am working in android app in which Login is not working on Authorize.net on android </p>

<p>below is my code.......... any help is highly appreciated.</p>

<pre><code>        public class MobileMerchantAuthActivity extends AuthNetActivityBase {

    protected static final int MERCHANT_CREDENTIALS_SUBACTIVITY = 0x300;

    public static final String EXTRA_MERCHANT = "authnet_merchant";
    public static final String EXTRA_ACCOUNT_PERMISSIONS = "authnet_account_permissions";
    public static final String EXTRA_MERCHANT_CONTACT = "authnet_merchant_contact";
    public static final String EXTRA_SESSION_KEY_INVALID = "authnet_session_key_invalid";
    public static final String EXTRA_LOGOUT_IN_PROGRESS = "authnet_logout_in_progress";

    // merchant window
    public static final String EXTRA_MERCHANT_CREDENTIALS_LAYOUT_ID = "authnet_merchant_credentials_layout_id";
    public static final String EXTRA_MERCHANT_CREDENTIALS_LOGIN_EDIT_ID = "authnet_merchant_credentials_login_edit_id";
    public static final String EXTRA_MERCHANT_CREDENTIALS_PASSWORD_EDIT_ID = "authnet_merchant_credentials_password_edit_id";
    public static final String EXTRA_MERCHANT_CREDENTIALS_CANCEL_BUTTON_ID = "authnet_merchant_credentials_cancel_button_id";
    public static final String EXTRA_MERCHANT_CREDENTIALS_VALIDATE_BUTTON_ID = "authnet_merchant_credentials_validate_button_id";

    private String deviceTelephoneNumber = "";
    private String deviceId;
    private static Context context;
    private static Merchant _merchant;
    private ProgressDialog loggingInDialog;
    private AlertDialog alertDialog;
    private String deviceDescription;
    private EditText loginIdEdit;
    private EditText passwordEdit;

    /**
    * Called when the activity is first created.
    */
    @Override
    public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    // get the environment that this is running against
    context = this;
    setDeviceIdentifiers();
    // determine if the mint credentials page needs to be shown
    if (!getIntent().getBooleanExtra(EXTRA_LOGOUT_IN_PROGRESS, false) &amp;&amp;
    (_merchant == null || getIntent().getBooleanExtra(
    EXTRA_SESSION_KEY_INVALID, false)) ) {
    showCredentialsPage();
    } else {
    setResultIntent();
    }
    }

    /**
    * Load the login ID and password prompt page.
    */
    public void showCredentialsPage() {
    int merchantCredentialsLayoutId = getIntent().getIntExtra(
    EXTRA_MERCHANT_CREDENTIALS_LAYOUT_ID, -1);

    if (merchantCredentialsLayoutId != -1) {
    setContentView(merchantCredentialsLayoutId);

    loginIdEdit = (EditText) findViewById(getIntent().getIntExtra(
    EXTRA_MERCHANT_CREDENTIALS_LOGIN_EDIT_ID, -1));
    passwordEdit = (EditText) findViewById(getIntent().getIntExtra(
    EXTRA_MERCHANT_CREDENTIALS_PASSWORD_EDIT_ID, -1));

    if (loginIdEdit != null) {
    loginIdEdit.setText("");
    }
    if (passwordEdit != null) {
    passwordEdit.setText("");
    }

    // hook up cancel
    View cancelButton = findViewById(getIntent().getIntExtra(
    EXTRA_MERCHANT_CREDENTIALS_CANCEL_BUTTON_ID, -1));
    if (cancelButton != null) {
    cancelButton.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
    setResult(RESULT_CANCELED);
    finish();
    }
    });
    }

    // hook up login
    View validateButton = findViewById(getIntent().getIntExtra(
    EXTRA_MERCHANT_CREDENTIALS_VALIDATE_BUTTON_ID, -1));

    if (validateButton != null) {
    validateButton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
    showLoggingInDialog();
    PasswordAuthentication passAuth = PasswordAuthentication
    .createMerchantAuthentication(loginIdEdit.getText().toString(),
    passwordEdit.getText().toString(), deviceId);
    Log.e("ExecuteTransactionTask","Merchant is abc"+_merchant );
    // System.out.println("DeviceID: "+deviceId);
    // PasswordAuthentication passAuth = PasswordAuthentication
    // .createMerchantAuthentication(BillingInfoConstants.MARCHENT_ID,
    // BillingInfoConstants.MARCHENT_PASSWORD, deviceId);
    _merchant = Merchant.createMerchant(env, passAuth);
    Log.e("ExecuteTransactionTask","Merchant is "+_merchant );
    new ExecuteTransactionTask().execute();
    }
    });
    }
    }
    }

    /**
    * Create an AsyncTask to perform the transaction request.
    *
    */
    protected class ExecuteTransactionTask extends
    AsyncTask&lt;Object, Void, Integer&gt; {
    @Override
    protected void onPreExecute() {
    super.onPreExecute();
    Log.e("ExecuteTransactionTask", "ExecuteTransactionTask started");
    }
    @Override
    protected Integer doInBackground(Object... args) {
    int resultCode;
    Log.e("ExecuteTransactionTask", "ExecuteTransactionTask doInBackground");
    try {
    net.authorize.mobile.Transaction transaction = _merchant
    .createMobileTransaction(TransactionType.MOBILE_DEVICE_LOGIN);
    MobileDevice mobileDevice = MobileDevice.createMobileDevice(deviceId,
    deviceDescription, deviceTelephoneNumber);
    transaction.setMobileDevice(mobileDevice);
    result = (net.authorize.mobile.Result) _merchant
    .postTransaction(transaction);

    // if the device hasn't been registered, register now and go from there
    if (result.isResponseError()
    &amp;&amp; (result.getMessages().size() == 1 &amp;&amp; MessageType.E00054
    .equals(result.getMessages().get(0)))) {
    transaction = _merchant
    .createMobileTransaction(TransactionType.MOBILE_DEVICE_REGISTRATION);
    transaction.setMobileDevice(mobileDevice);
    result = (net.authorize.mobile.Result) _merchant
    .postTransaction(transaction);

    // attempt login again
    transaction = _merchant
    .createMobileTransaction(TransactionType.MOBILE_DEVICE_LOGIN);
    transaction.setMobileDevice(mobileDevice);
    result = (net.authorize.mobile.Result) _merchant
    .postTransaction(transaction);
    }
    resultCode = result.isResponseOk() ? RESULT_OK
    : SimpleActivity.RESULT_FAILURE;
    } catch (Exception e) {
    e.printStackTrace();
    Log.e(this.getClass().getName(), "executeTransaction failed.", e);
    resultCode = SimpleActivity.RESULT_FAILURE;
    }

    return resultCode;
    }

    @Override
    protected void onPostExecute(Integer resultCode) {
    Log.e("ExecuteTransactionTask", "ExecuteTransactionTask onPostExecute");
    switch (resultCode) {
    case RESULT_CANCELED:
    setResult(RESULT_CANCELED);
    dismissLoggingInDialog();
    finish();
    break;
    case SimpleActivity.RESULT_FAILURE:
    if (result != null) {
    showAlert(result.getMessages().size() &gt; 0 ? result.getMessages()
    .get(0).getText() : MessageType.E00000.getText());
    } else {
    setResult(SimpleActivity.RESULT_FAILURE);
    dismissLoggingInDialog();
    finish();
    }
    break;
    case RESULT_OK:

    // check if the result was from a registration or a successful login
    AuthNetActivityBase.sessionToken = result.getSessionToken();
    SessionTokenAuthentication sessionTokenAuthentication = SessionTokenAuthentication
    .createMerchantAuthentication(_merchant.getMerchantAuthentication()
    .getName(), result.getSessionToken(), deviceId);
    _merchant.setMerchantAuthentication(sessionTokenAuthentication);
    setResultIntent();
    break;
    }
    }

    /**
    * Show a alert message.
    *
    * @param title
    * @param message
    */
    public void showAlert(String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(message).setPositiveButton("OK",
    new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
    dismissLoggingInDialog();
    }
    });
    alertDialog = builder.create();
    alertDialog.show();
    }

    }

    @Override
    public void onActivityResult(int correlationId, int resultCode, Intent data) {

    try {
    switch (correlationId) {
    case MERCHANT_CREDENTIALS_SUBACTIVITY:
    switch (resultCode) {
    case Activity.RESULT_CANCELED:
    _merchant = null;
    finish();
    break;
    case Activity.RESULT_OK:
    _merchant = (Merchant) data.getSerializableExtra(EXTRA_MERCHANT);
    break;
    default:
    Log.e(MobileMerchantAuthActivity.class.getName(),
    "Couldn't find callback handler for correlationId: "
    + correlationId);
    }
    break;
    }
    } catch (Exception e) {
    Log.e(MobileMerchantAuthActivity.class.getName(),
    "Problem processing result from sub-activity", e);
    }
    }

    /**
    * Populates the result with intent data.
    */
    protected void setResultIntent() {

    if (_merchant != null) {
    Intent intentResult = new Intent();
    intentResult.putExtra(EXTRA_MERCHANT, _merchant);
    if (result != null) {
    net.authorize.mobile.Result mobileResult = (net.authorize.mobile.Result) result;

    // add the user permissions
    if (mobileResult.getUserPermissions() != null) {
    intentResult.putExtra(EXTRA_ACCOUNT_PERMISSIONS,
    mobileResult.getUserPermissions());
    }
    // add the merchant contact info
    if (mobileResult.getMerchantContact() != null) {
    intentResult.putExtra(EXTRA_MERCHANT_CONTACT,
    mobileResult.getMerchantContact());
    }
    }
    setResult(RESULT_OK, intentResult);
    }
    dismissLoggingInDialog();
    finish();
    }

    /**
    * Setup the "Logging in" dialog.
    */
    public void setupLoggingInDialog() {
    if (loggingInDialog != null) {
    loggingInDialog.dismiss();
    }
    loggingInDialog = new ProgressDialog(this);
    loggingInDialog.setMessage("Logging in...");
    loggingInDialog.setIndeterminate(true);
    loggingInDialog.setCancelable(false);
    }

    /**
    * Show the "Logging in" dialog.
    */
    public void showLoggingInDialog() {
    setupLoggingInDialog();
    if (loggingInDialog != null &amp;&amp; !loggingInDialog.isShowing()) {
    loggingInDialog.show();
    }
    }

    /**
    * Dismiss the "Logging in" dialog.
    */
    public void dismissLoggingInDialog() {
    if (loggingInDialog != null &amp;&amp; loggingInDialog.isShowing()) {
    loggingInDialog.dismiss();
    }
    }

    /**
    * To support the fragmentation of device identifiers, this method is being
    * used to attempt the retrieval of unique device information.
    */
    private void setDeviceIdentifiers() {
    StringBuilder deviceDescriptionBuilder = new StringBuilder("Android(");
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    boolean wifiEnabled = false;
    try {
    wifiEnabled = wm.isWifiEnabled();
    } catch (SecurityException se) {
    }

    if (StringUtils.isNotEmpty(tm.getDeviceId())) {
    System.out.println("DeviceID: "+tm.getDeviceId());
    switch (tm.getPhoneType()) {
    case TelephonyManager.PHONE_TYPE_CDMA:
    deviceDescriptionBuilder.append("CDMA-");
    break;
    case TelephonyManager.PHONE_TYPE_GSM:
    deviceDescriptionBuilder.append("GSM-");
    break;
    default:
    deviceDescriptionBuilder.append("X-");
    break;
    }
    deviceDescriptionBuilder.append(tm.getNetworkCountryIso()).append("-");
    deviceDescriptionBuilder.append(tm.getNetworkOperator()).append("-");
    deviceDescriptionBuilder.append(tm.getNetworkOperatorName()).append(")");
    deviceDescription = deviceDescriptionBuilder.substring(0,
    deviceDescriptionBuilder.length() &gt; 60 ? 60
    : deviceDescriptionBuilder.length());
    deviceId = "Android_" + tm.getDeviceId() + "_" + tm.getSimSerialNumber();
    deviceTelephoneNumber = tm.getLine1Number();

    }
    // wifi only device?
    else if (wifiEnabled) {
    deviceDescriptionBuilder.append("WIFI-");
    deviceDescriptionBuilder.append(wm.getConnectionInfo().getMacAddress());
    deviceDescriptionBuilder.append(")");
    }
    // other unknown
    else {
    deviceDescriptionBuilder.append("UNKNOWN_NETWORK)");
    }
    deviceDescription = deviceDescriptionBuilder.toString();

    // if the device id is null, populate it with other known possible values
    if (StringUtils.isEmpty(deviceId)) {
    String androidId = Secure.getString(getContentResolver(),
    Secure.ANDROID_ID);
    deviceId = "Android.NOPHONE_" + androidId;
    // if (Build.VERSION.SDK_INT &gt; 8) {
    // deviceId += "_" + android.os.Build.SERIAL;
    // }
    }

    }

    }
</code></pre>
