Skip to content

Commit

Permalink
Do country code detection if we can't get the full number off SIM.
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie0 committed Jun 4, 2014
1 parent db356a0 commit df1c96a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/org/thoughtcrime/securesms/RegistrationActivity.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.thoughtcrime.securesms;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
Expand Down Expand Up @@ -104,17 +106,23 @@ public boolean onTouch(View v, MotionEvent event) {
}

private void initializeNumber() {
String localNumber = org.whispersystems.textsecure.util.Util.getDeviceE164Number(this);
PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance();
String localNumber = org.whispersystems.textsecure.util.Util.getDeviceE164Number(this);

try {
if (!Util.isEmpty(localNumber)) {
PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance();
Phonenumber.PhoneNumber localNumberObject = numberUtil.parse(localNumber, null);

if (localNumberObject != null) {
this.countryCode.setText(localNumberObject.getCountryCode()+"");
this.number.setText(localNumberObject.getNationalNumber()+"");
}
} else {
String simCountryIso = ((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).getSimCountryIso();

if (!Util.isEmpty(simCountryIso)) {
this.countryCode.setText(numberUtil.getCountryCodeForRegion(simCountryIso.toUpperCase())+"");
}
}
} catch (NumberParseException npe) {
Log.w("CreateAccountActivity", npe);
Expand Down

1 comment on commit df1c96a

@WhisperBTC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! BitHub has sent payment of $39.57USD for this commit.

Please sign in to comment.