fbritop Well-Known Member Licensed User Longtime User Aug 28, 2020 #1 I have the following code in B4A B4X: Copy Dim n As String="5699126532" Dim r As Reflector n=(r.RunStaticMethod("android.telephony.PhoneNumberUtils", "formatNumber", Array As Object("+" & n, Null), Array As String("java.lang.String", "java.lang.String"))) Which gives me a correct output: For 56991296532 it gets 56 9 9129 6532 For 5491133954455 it gets 54 9 11 3395-4455 Both outputs are correct, as it is the way each country formats the number. Is there any similar function I can achieve this results in B4I? Thanks
I have the following code in B4A B4X: Copy Dim n As String="5699126532" Dim r As Reflector n=(r.RunStaticMethod("android.telephony.PhoneNumberUtils", "formatNumber", Array As Object("+" & n, Null), Array As String("java.lang.String", "java.lang.String"))) Which gives me a correct output: For 56991296532 it gets 56 9 9129 6532 For 5491133954455 it gets 54 9 11 3395-4455 Both outputs are correct, as it is the way each country formats the number. Is there any similar function I can achieve this results in B4I? Thanks
Erel B4X founder Staff member Licensed User Longtime User Aug 28, 2020 #2 libPhoneNumber Is there anything similar to the b4a phoneValidator https://www.b4x.com/android/forum/threads/b4a-and-b4j-phonevalidator-library.94014/#post-618013 based on: https://github.com/google/libphonenumber a or any simple way of porting a Java Lib to B4I lib? Thanks FBP www.b4x.com Upvote 0
libPhoneNumber Is there anything similar to the b4a phoneValidator https://www.b4x.com/android/forum/threads/b4a-and-b4j-phonevalidator-library.94014/#post-618013 based on: https://github.com/google/libphonenumber a or any simple way of porting a Java Lib to B4I lib? Thanks FBP www.b4x.com
fbritop Well-Known Member Licensed User Longtime User Aug 28, 2020 #3 Thanks I´m aware of that old thread on mine, but as you always tell us. "Start a new thread for this question"... was strictly followed. Anyway, I have that function at it works OK, the only thing is that you need to be updating the lib every while. But the end question in not looking if the number is valid, but format the output (according to the country code +56/+54 for example. I remember have given a try to libPhoneNumber some time ago, but I could not resolve how to get the formatting done (I´m almost close to null when it comes to OBJC Thanks Again Upvote 0
Thanks I´m aware of that old thread on mine, but as you always tell us. "Start a new thread for this question"... was strictly followed. Anyway, I have that function at it works OK, the only thing is that you need to be updating the lib every while. But the end question in not looking if the number is valid, but format the output (according to the country code +56/+54 for example. I remember have given a try to libPhoneNumber some time ago, but I could not resolve how to get the formatting done (I´m almost close to null when it comes to OBJC Thanks Again
Semen Matusovskiy Well-Known Member Licensed User Aug 28, 2020 #4 For example, you want to format international number. 1) Start B4I, create a new "Default" project. Set your bundle id and add to Project Attributes Code: Copy #CertificateFile : your.cer ' <- Change #ProvisionFile : your.mobileprovision ' <- Change #AdditionalLib: libPhoneNumberiOS.framework.swift.3 2) Add following code to the bottom of the module Code: Copy #if OBJC #import <libPhoneNumberiOS/libPhoneNumberiOS.h> - (NSString*) PhoneInternational: (NSString*) Number : (NSString*) DefaultRegion { NBPhoneNumberUtil *phoneUtil = [[NBPhoneNumberUtil alloc] init]; NSError *anError = nil; NSString *answer = nil; NBPhoneNumber *myNumber = [phoneUtil parse: Number defaultRegion: DefaultRegion error: &anError]; if (anError == nil) { answer = [phoneUtil format: myNumber numberFormat: NBEPhoneNumberFormatINTERNATIONAL error: &anError]; }; if (anError != nil) { answer = [anError localizedDescription]; }; return answer; } #End If 3) Add call to Application_Start subroutine Code: Copy Dim nme As NativeObject = Me Log (nme.RunMethod ("PhoneInternational::", Array ("+5491133954455", "")).AsString) Run on iPhone. The result (in Log) will be +54 9 11 3395-4455 You can specify national number also (without + and country code), but in this case you must specify a region: Code: Copy Log (nme.RunMethod ("PhoneInternational::", Array ("0111533954455", "AR")).AsString) If you want output as national number, replace NBEPhoneNumberFormatINTERNATIONAL to NBEPhoneNumberFormatNATIONAL. In this case output will be 011 15-3395-4455 Last edited: Aug 28, 2020 Upvote 0
For example, you want to format international number. 1) Start B4I, create a new "Default" project. Set your bundle id and add to Project Attributes Code: Copy #CertificateFile : your.cer ' <- Change #ProvisionFile : your.mobileprovision ' <- Change #AdditionalLib: libPhoneNumberiOS.framework.swift.3 2) Add following code to the bottom of the module Code: Copy #if OBJC #import <libPhoneNumberiOS/libPhoneNumberiOS.h> - (NSString*) PhoneInternational: (NSString*) Number : (NSString*) DefaultRegion { NBPhoneNumberUtil *phoneUtil = [[NBPhoneNumberUtil alloc] init]; NSError *anError = nil; NSString *answer = nil; NBPhoneNumber *myNumber = [phoneUtil parse: Number defaultRegion: DefaultRegion error: &anError]; if (anError == nil) { answer = [phoneUtil format: myNumber numberFormat: NBEPhoneNumberFormatINTERNATIONAL error: &anError]; }; if (anError != nil) { answer = [anError localizedDescription]; }; return answer; } #End If 3) Add call to Application_Start subroutine Code: Copy Dim nme As NativeObject = Me Log (nme.RunMethod ("PhoneInternational::", Array ("+5491133954455", "")).AsString) Run on iPhone. The result (in Log) will be +54 9 11 3395-4455 You can specify national number also (without + and country code), but in this case you must specify a region: Code: Copy Log (nme.RunMethod ("PhoneInternational::", Array ("0111533954455", "AR")).AsString) If you want output as national number, replace NBEPhoneNumberFormatINTERNATIONAL to NBEPhoneNumberFormatNATIONAL. In this case output will be 011 15-3395-4455
fbritop Well-Known Member Licensed User Longtime User Aug 29, 2020 #5 Thanks @Semen Matusovskiy that was exactly what I was looking for! Cheers Upvote 0
Semen Matusovskiy Well-Known Member Licensed User Aug 29, 2020 #6 It were some changes in library since https://www.b4x.com/android/forum/threads/libphonenumber.114678/#post-716518 I compiled the latest release. Supports iPhones and simulators. Upvote 0
It were some changes in library since https://www.b4x.com/android/forum/threads/libphonenumber.114678/#post-716518 I compiled the latest release. Supports iPhones and simulators.
Erel B4X founder Staff member Licensed User Longtime User Aug 30, 2020 #7 fbritop said: I´m aware of that old thread on mine, but as you always tell us. "Start a new thread for this question"... was strictly followed. Click to expand... Worth posting a link to the original thread in such case. Upvote 0
fbritop said: I´m aware of that old thread on mine, but as you always tell us. "Start a new thread for this question"... was strictly followed. Click to expand... Worth posting a link to the original thread in such case.
fbritop Well-Known Member Licensed User Longtime User Sep 3, 2020 #8 Semen Matusovskiy said: It were some changes in library since https://www.b4x.com/android/forum/threads/libphonenumber.114678/#post-716518 I compiled the latest release. Supports iPhones and simulators. Click to expand... Is it neccesary when I use the remote compiler or just for local compile? Thanks FBP Upvote 0
Semen Matusovskiy said: It were some changes in library since https://www.b4x.com/android/forum/threads/libphonenumber.114678/#post-716518 I compiled the latest release. Supports iPhones and simulators. Click to expand... Is it neccesary when I use the remote compiler or just for local compile? Thanks FBP
Semen Matusovskiy Well-Known Member Licensed User Sep 3, 2020 #9 If you use local builder, you can simply copy this framework to Libs subfolder. For hosted builder you need to ask Erel. Upvote 0
If you use local builder, you can simply copy this framework to Libs subfolder. For hosted builder you need to ask Erel.