Phone number formatting on iOS

This will help you Format (xxx) xxx-xxxx – (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { int length = (int)[self getLength:textField.text]; //NSLog(@”Length = %d “,length); if(length == 10) { if(range.length == 0) return NO; } if(length == 3) { NSString *num = [self formatNumber:textField.text]; textField.text = [NSString stringWithFormat:@”(%@) “,num]; if(range.length > 0) textField.text = [NSString stringWithFormat:@”%@”,[num substringToIndex:3]]; … Read more

Calling a phone number in swift

Just try: if let url = NSURL(string: “tel://\(busPhone)”) where UIApplication.sharedApplication().canOpenURL(url) { UIApplication.sharedApplication().openURL(url) } assuming that the phone number is in busPhone. NSURL‘s init(string:) returns an Optional, so by using if let we make sure that url is a NSURL (and not a NSURL? as returned by the init). For Swift 3: if let url = … Read more

How do I get the dialer to open with phone number displayed?

Two ways to achieve it. 1) Need to start the dialer via code, without user interaction. You need Action_Dial, use below code it will open Dialer with number specified Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse(“tel:0123456789”)); startActivity(intent); The ‘tel:’ prefix is required, otherwhise the following exception will be thrown: java.lang.IllegalStateException: Could not execute method of the … Read more

Read all contacts’ phone numbers in android

Following code shows an easy way to read all phone numbers and names: Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null); while (phones.moveToNext()) { String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); } phones.close(); NOTE: getContentResolver is a method from the Activity context.

Programmatically obtain the phone number of the Android phone

Code: TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE); String mPhoneNumber = tMgr.getLine1Number(); Required Permission: <uses-permission android:name=”android.permission.READ_PHONE_STATE”/> Caveats: According to the highly upvoted comments, there are a few caveats to be aware of. This can return null or “” or even “???????”, and it can return a stale phone number that is no longer valid. If you want something … Read more

MSISDN : Is it a SIM Card Data? Why all The Provided Function (from Blackberry and Android) to fetch MSISDN not reliable?

I have some insight into the matter for you. The MSISDN can be stored on the SIM card, however most network providers (all providers in South Africa) do not store the MSISDN on the SIM card. There are several reasons for this, the most notable being: Dynamic MSISDN allocation: Prepaid SIMs are sometime allocated an … Read more