Code example for TelephonyManager

Methods: getLine1Number, getSimCountryIso

0
	 
	// Requires android.permission.READ_PHONE_STATE 
	private String getMyPhoneNumber() {
	    TelephonyManager mTelephonyMgr;
	    mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
	    String num = mTelephonyMgr.getLine1Number();
	     
	    // MSISDN should not have a +, but some phones return it with a + 
	    // We want to see a + 
	    if(num != null && num.length() > 0 && !(num.charAt(0) == '+'))
	    	num = "+" + num;
	     
	    /* if(num == null || num.length() == 0) { 
	    	PhoneHelper ph = new PhoneHelper(); 
	    	ph.init(this); 
	    	num = ph.getLine1Number(); 
	    } */ 
	     
	    if(num == null || num.length() == 0) 
	    	num = "+" + getCountryCode(mTelephonyMgr.getSimCountryIso());
	     
	    return num;
	} 
	 
	// TODO: all ISO country codes