0

in my android app i have an SQLite Database with phone number (here I changed the numbers with other inexistent for privacy)!

mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToRead();

I created a List containing the numbers from database and printed on the screen to see if it works and it give me back correct the numbers!

List numeri = mySQLiteAdapter.getAllNumeri();
System.out.println("num tel: " + phone);

It give me back two numbers present in database --> [3401234567, 02123456]

Then i tryed to compare the incoming number of a call with this List with this metod:

String phone = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
System.out.println("Incoming number - " + phone);

    boolean retval = numeri.contains(phone); 

    if (retval == true) {
      System.out.println("PHONE is contained in the list");
     }
    else {
      System.out.println("PHONE is not contained in the list");
     }

I tryed to call with my number 3401234567!

The println give me back: Incoming number: +393401234567

and

The condition give me back that "PHONE is not contained in the list!"

I tryed also to change database numbers by adding the national prefix (+39) but it don t works!

Can anyone help me? Thanks

I think it isn t duplicate because in other question, compare two string, here i want compare one string with arraylist

Marc C
  • 73
  • 1
  • 8
  • U're doing it right, you may try to debug the code that's what i recommend – Nitin Misra Dec 07 '14 at 16:50
  • You should select the number from ur database instead of selecting all and then do list search. For example when u get the number do a selection statement that retuens that number if found else it doesn't – Kosh Dec 07 '14 at 16:52
  • @k0sh you can give me an help with this example??? – Marc C Dec 07 '14 at 17:02

1 Answers1

0

Did you check the return type of

mySQLiteAdapter.getAllNumeri()  

if its number, then the below statement might not give the desired output as you are trying to compare the numbers with the Strings.

boolean retval = numeri.contains(phone); 
Shiv
  • 689
  • 8
  • 23