How to get Contact by phone number?

androidsoftcoder

Member
Licensed User
Longtime User
I can't find direct function which can find contact by phone number only :(

Of course, I can build full phone listing and scan it for given phone number. But may be is more easy way?

I need at first, scan contacts, select some phone number, and later get for example this contact photo. But, after storing phone number, contact may be deleted and inserted other contact with the same number. I want to find this new contact by previously stored phone number by easiest way.
 

lymey

Active Member
Licensed User
Longtime User
Contacts Photo to Database

I am trying to do exactly that, but can't seem to work out how to take the contact photo and convert it to a blob using the example in the SQL tutorial.

That example shows using InputStream, and OutputStream, which I totally get. But the photo is already extracted from the contacts photo and stored as a Bitmap.
I think it would be the same as if I created a bitmap with a drawing app and wanted to save it in a SQL database.

This is the tutorial example:
Dim InputStream1 As InputStream
InputStream1 = File.OpenInput(File.DirAssets, "smiley.gif")
Dim OutputStream1 As OutputStream
OutputStream1.InitializeToBytesArray(1000)
File.Copy2(InputStream1, OutputStream1)
Dim Buffer() As Byte
Buffer = OutputStream1.ToBytesArray

'write the image to the database
SQL1.ExecNonQuery2("INSERT INTO table2 VALUES('smiley', ?)", Array As Object(Buffer))

But I am obtaining the Bitmap like this:
Dimmed in Process Globals:
Dim ImageFromContacts As Bitmap
Dim Contact_Image() As Byte
Dim Single_Phone_Contact_photo As Bitmap

'Part of Contacts extraction:
Single_Phone_Contact_photo = Single_Phone_Contact.GetPhoto
If Single_Phone_Contact_photo <> Null Then
'convert for Db

ImageFromContacts = Single_Phone_Contact_photo
ConvertImageToBlob

Sub ConvertImageToBlob
'convert the image file to a bytes array
Dim InputStream1 As InputStream

InputStream1 = ImageFromContacts
Dim OutputStream1 As OutputStream
OutputStream1.InitializeToBytesArray(1000)
File.Copy2(ImageFromContacts, OutputStream1)
Contact_Image = OutputStream1.ToBytesArray


End Sub

Naturally there is a Java IO error since there is no file directory data.

Am I totally missing something? (Probably!)
 
Upvote 0

lymey

Active Member
Licensed User
Longtime User
errata

Sorry this is what I have in the ConvertImageToBlob sub:

Sub ConvertImageToBlob
'convert the image file to a bytes array
Dim InputStream1 As InputStream

InputStream1 = ImageFromContacts
Dim OutputStream1 As OutputStream
OutputStream1.InitializeToBytesArray(1000)
File.Copy2(InputStream1, OutputStream1)
Contact_Image = OutputStream1.ToBytesArray


End Sub
 
Upvote 0
Top