Java Question libphonenumber/

Firpas

Active Member
Licensed User
Longtime User
Hi Erel,
I am also creating a library for B4A based in http://code.google.com/p/libphonenumber/

Here is my code:
B4X:
package com.firpas.fmphonevalidator;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import com.google.i18n.phonenumbers.*;
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberType;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import android.util.Log;
@DependsOn(values=("libphonenumbers-7.0"))
@ShortName("FMPhoneValidator")
@Version(1)
@Author("Firpas")
public class FMPhoneValidator {
    private PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
   
    public boolean Validate(String phoneNumber, String defaultCountry){
        boolean Resp = false;
        try {
              PhoneNumber number = phoneUtil.parseAndKeepRawInput(phoneNumber, defaultCountry);
              boolean isPossible = phoneUtil.isPossibleNumber(number);
              boolean isNumberValid = phoneUtil.isValidNumber(number);
              PhoneNumberType numberType = phoneUtil.getNumberType(number);
              boolean hasDefaultCountry = !defaultCountry.isEmpty() && defaultCountry != "ZZ";
              Resp = phoneUtil.isValidNumber(number);
        } catch (Exception e){
            Log.w("B4A", Log.getStackTraceString(e));
        }
        return Resp;
    }
}
I have a copy of libphonenumbers-7.0.jar in my b4a additional library folder
I use Simple Library Compiler (v1.03) to compile it but i have this error message
Starting step: Compiling Java code.
javac 1.8.0_65
D:\Fuentes\EclipseWorkspace\FMPhoneValidatod\src\com\firpas\fmphonevalidator\FMPhoneValidator.java:8: error: package com.google.i18n.phonenumbers does not exist
import com.google.i18n.phonenumbers.PhoneNumberUtil;
^
1 error

Error.
What is my mistake??
Thanks in advance
 

DonManfred

Expert
Licensed User
Longtime User
What is my mistake??
Do you use SLC to compile?
If yes then add
,com.google
at the end of the "ba-Ignore" inputfield.
Compile again.
dont forget to copy libphonenumbers-7.0.jar to your additional library folder.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Erel,
I am also creating a library for B4A based in http://code.google.com/p/libphonenumber/

Here is my code:
B4X:
package com.firpas.fmphonevalidator;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import com.google.i18n.phonenumbers.*;
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberType;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import android.util.Log;
@DependsOn(values=("libphonenumbers-7.0"))
@ShortName("FMPhoneValidator")
@Version(1)
@Author("Firpas")
public class FMPhoneValidator {
    private PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
  
    public boolean Validate(String phoneNumber, String defaultCountry){
        boolean Resp = false;
        try {
              PhoneNumber number = phoneUtil.parseAndKeepRawInput(phoneNumber, defaultCountry);
              boolean isPossible = phoneUtil.isPossibleNumber(number);
              boolean isNumberValid = phoneUtil.isValidNumber(number);
              PhoneNumberType numberType = phoneUtil.getNumberType(number);
              boolean hasDefaultCountry = !defaultCountry.isEmpty() && defaultCountry != "ZZ";
              Resp = phoneUtil.isValidNumber(number);
        } catch (Exception e){
            Log.w("B4A", Log.getStackTraceString(e));
        }
        return Resp;
    }
}
I have a copy of libphonenumbers-7.0.jar in my b4a additional library folder
I use Simple Library Compiler (v1.03) to compile it but i have this error message

What is my mistake??
Thanks in advance
I think you are missing the "libs" folder in your Java project. You should create a libs folder on the same folder level as the "src" folder and copy "libphonenumbers-7.0.jar" into the "libs" folder else it will give you the error that you are getting at present. The jar needs to be in your additional library folder for your B4A project to work but it also needs to be in the "libs" folder of your Java project in order to compile the Java project.
 

Firpas

Active Member
Licensed User
Longtime User
Hi DonManfred

Thanks for your replay

Yes, i use SLC to compile, but i dont undertand ...
where is "ba-Ignore" inputfield??
 

Firpas

Active Member
Licensed User
Longtime User
Hi Johan,

as you can see in the attached image, I added the lib folder with the jar file.

However, reference to the library is set to copy on additional library folder
 

Attachments

  • img1.png
    152.6 KB · Views: 554

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

as you can see in the attached image, I added the lib folder with the jar file.

However, reference to the library is set to copy on additional library folder
The folder must be called libs and not just lib.
And then when you compile it with SLC you need to enter ,com.google in SLC's -b4aignore input field
 

Firpas

Active Member
Licensed User
Longtime User
Thank you very much Johan.

The folder named lib (instead of libs) was my mistake.

All is ok now.

Thanks you again
 

JohnC

Expert
Licensed User
Longtime User
Hi Firpas,

Did you release this library yet?

I need to validate phone numbers in my app and this lib would be useful :)
 

JimmyQG

New Member
Licensed User
Longtime User
I am also looking for the same library. If Firpas or someone else already created it successfully, it will be helpful if you share it.
 

JackKirk

Well-Known Member
Licensed User
Longtime User
I never cease to be amazed at the B4X products and community and have finally found a way to repay some of the support I have received over the last couple of years.

The fact I also need this functionality is beside the point :):):)

Never done a library before but seeing as how no one else seems willing to bring this thread to its logical conclusion I thought I'd give it a go.

Simply by installing SLC and joining the dots in the above posts I have come up with the following little library.

Usage:
B4X:
Private Sub Process_Globals
    Private Obj_phonevalidator As PhoneValidator
End Sub

Private Sub FOO_sub(phoneno As String)
    Private good_no as Boolean = Obj_phonevalidator.Validate(phoneno, "AU")
End Sub
AU is the default country code - always uppercase, AU = Australia, US = ...

If you specify a default country code then you can test phone nos using the nomenclature internal to that country.

If you set default country code to "" then all phone nos to be tested must be in E.164 format (https://en.wikipedia.org/wiki/E.164) otherwise result will be false.

You must also install libphonenumber-8.9.7.jar (as at writing - the latest and greatest) to your B4A additional libraries folder, I got it from:

https://mvnrepository.com/artifact/com.googlecode.libphonenumber/libphonenumber/8.9.7

Enjoy...
 

Attachments

  • phonevalidator.zip
    1.6 KB · Views: 329

JackKirk

Well-Known Member
Licensed User
Longtime User
Erel,

Should I repost it and delete it from here?
 
Top