B4A Library Get contact ID or name from Phone number

This is my first library

Thank you XverhelstX, Erel and mlc (who wrote most of it) for your help

This library only has 2 subs

GetContactNamebyPhone(String phonenumber)
GetContactIDbyPhone(String phonenumber)

This is useful to bypass Android's bug of reporting -1 as the contact id for SMS messages, as well as not needing a database of phone numbers to do a reverse lookup
 

Attachments

  • Technis.zip
    1.8 KB · Views: 1,123

bsnqt

Active Member
Licensed User
Longtime User
This is my first library

Thank you XverhelstX, Erel and mlc (who wrote most of it) for your help

This library only has 2 subs

GetContactNamebyPhone(String phonenumber)
GetContactIDbyPhone(String phonenumber)

This is useful to bypass Android's bug of reporting -1 as the contact id for SMS messages, as well as not needing a database of phone numbers to do a reverse lookup

I did face with such issue so thanks a lot for having shared this library NeoTechni.
 

isr

Member
Licensed User
Longtime User
No memory and NullPointer exceptions in library

First, thank you to NeoTechni, mlc, Erel, and XverhelstX for laying the foundation to and creating the Technis library. :sign0098: I ended up using it because the database approach I developed was far too resource intensive (often causing my app to crash).

I use the Technis library to identify the names associated with SMS as my app reads in the messages from the SMS log (SMSMessages). For some users, the log may contain hundreds or thousands of messages, and the app loops through the messages one at a time. In each cycle of the loop, the app calls GetContactByPhone from the Technis library. When there are few messages in SMSMessages (such as fewer than 100), no problems occur. However when there are several hundred or more messages in SMSMessages, the No memory and NullPointer exceptions occur, after 150 or more messages have been processed successfully.

Here's the key part of the code:
B4X:
Dim contactnames As Technis
.
.
.
'looping through individual messages in SMSMessages
'address = a cleaned version of the address (phone number) for a particular text message

Try
  textname=contactnames.GetContactByPhone(address)
Catch
  Log(LastException.Message)
End Try

Here is the trace output for the exceptions logged when this problem occurs:

binder=0x7b49f8 transaction failed fd=-2147483647, size=0, err=-2147483646
(Unknown error: 2147483646)
cannot dup fd=-2147483647, size=0, err=-2147483646 (Bad file number)
cannot map BpMemoryHeap (binder=0x7b49f8), size=0, fd=-1 (Bad file number)
*** Uncaught remote exception! (Exceptions are not yet supported across
processes.)
java.lang.RuntimeException: No memory in memObj
at android.database.CursorWindow.native_init(Native Method)
at android.database.CursorWindow.<init>(CursorWindow.java:550)
at android.database.CursorWindow.<init>(CursorWindow.java:29)
at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:525)
at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:523)
at
android.content.ContentProviderNative.onTransact(ContentProviderNative.java:103)
at android.os.Binder.execTransact(Binder.java:320)
at dalvik.system.NativeStart.run(Native Method)
java.lang.NullPointerException

The content of the log output is the same for each separate time the exceptions occur, but only the binder value changes.

I don't know how to interpret this output. What is the source of the problem? And how can I avoid these errors?

Thank you for any advice you might have!
 

isr

Member
Licensed User
Longtime User
No, I didn't develop the library. I am simply a user of it. NeoTechni developed the library, based on mlc's ideas, I think.

What advice do you have for dealing with these errors?

Thank you!
 

isr

Member
Licensed User
Longtime User
Doesn't the output below (from my earlier post) show the errors that were caught?

binder=0x7b49f8 transaction failed fd=-2147483647, size=0, err=-2147483646
(Unknown error: 2147483646)
cannot dup fd=-2147483647, size=0, err=-2147483646 (Bad file number)
cannot map BpMemoryHeap (binder=0x7b49f8), size=0, fd=-1 (Bad file number)
*** Uncaught remote exception! (Exceptions are not yet supported across
processes.)
java.lang.RuntimeException: No memory in memObj
at android.database.CursorWindow.native_init(Native Method)
at android.database.CursorWindow.<init>(CursorWindow. java:550)
at android.database.CursorWindow.<init>(CursorWindow. java:29)
at android.database.CursorWindow$1.createFromParcel(C ursorWindow.java:525)
at android.database.CursorWindow$1.createFromParcel(C ursorWindow.java:523)
at
android.content.ContentProviderNative.onTransact(C ontentProviderNative.java:103)
at android.os.Binder.execTransact(Binder.java:320)
at dalvik.system.NativeStart.run(Native Method)
java.lang.NullPointerException

The content of the log output is the same for each separate time the exceptions occur, but only the binder value changes.

If it doesn't, could you please tell me what I need to do?

Thank you!
 

isr

Member
Licensed User
Longtime User
The app seemed to keep looping through the individual texts and logging these exceptions. I didn't actually run the test -- my tester did, who was 3 time zones away from me when he was testing. He gave up after several minutes of this logging, as he didn't know the app was still working. Once the app started logging exceptions, it continued to for all subsequent text messages in the loop.

When I didn't have the try/catch block in, the app did ultimately finish, but just without the results that rely on successful retrieval of contact names.

I hope I am making sense!
 

isr

Member
Licensed User
Longtime User
Thank you, Erel. This is the thread for the library.

It looks like I will need to invent a workaround that minimizes lookups. I'm guessing the library gets into trouble with the phone or the contacts list by attempting too many lookups too quickly. The contacts list really seems to be a big weak point in Android.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I have no idea. I haven't run into that annoyance.

I tried to put it on the wiki but it says I dont have an account.
 

DonManfred

Expert
Licensed User
Longtime User
How to use this library on the new version of b4a?
1. You should ALWAYS create a new thread for any question you have. Posting to existing threads is a mistake. Especially when the thread is seven years old. You should have seen a note telling you that.
2. What is the Error you get? <- Post it in the new thread.
 
Last edited:

Oke

Member
Licensed User
Longtime User
1. You should ALWAYS create a new thread for any question you have. Posting to existing threads is a mistake. Especially when the thread is seven years old. You should have seen a not telling you that.
2. What is the Error you get? <- Post it in the new thread.

ok, thank you
 
Top