roy89
Member
Hello, I'm trying to open the contact picker on my phone and have it return the selected contact to be added to my edittext4, but nothing happens. I select the contact and nothing happens. Can you help me?
Sub Button51_Click
rp.CheckAndRequest(rp.PERMISSION_READ_CONTACTS)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
Dim i As Intent
i.Initialize("android.intent.action.PICK", "content://com.android.contacts/data/phones")
StartActivity(i)
End If
End Sub
Sub Activity_Result (RequestCode As Int, ResultCode As Int, Data As Intent)
If ResultCode = -1 And Data.IsInitialized Then
Try
Dim cr As ContentResolver
cr.Initialize("")
Dim uriString As String = Data.GetData
Dim uri As Uri
uri.Parse(uriString)
Dim c As Cursor = cr.Query(uri, Array As String("data1"), "", Null, "")
If c.RowCount > 0 Then
c.Position = 0
Dim phoneNumber As String = c.GetString2(0)
c.Close
Dim cleanNumber As String = ""
For i = 0 To phoneNumber.Length - 1
Dim digit As String = phoneNumber.CharAt(i)
If digit >= "0" And digit <= "9" Then cleanNumber = cleanNumber & digit
Next
If cleanNumber.Length > 8 Then
cleanNumber = cleanNumber.SubString(cleanNumber.Length - 8)
End If
EditText4.Text = cleanNumber
ToastMessageShow("Número: " & cleanNumber, False)
Else
c.Close
End If
Catch
Log(LastException.Message)
End Try
End If
End Sub
Sub Button51_Click
rp.CheckAndRequest(rp.PERMISSION_READ_CONTACTS)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
Dim i As Intent
i.Initialize("android.intent.action.PICK", "content://com.android.contacts/data/phones")
StartActivity(i)
End If
End Sub
Sub Activity_Result (RequestCode As Int, ResultCode As Int, Data As Intent)
If ResultCode = -1 And Data.IsInitialized Then
Try
Dim cr As ContentResolver
cr.Initialize("")
Dim uriString As String = Data.GetData
Dim uri As Uri
uri.Parse(uriString)
Dim c As Cursor = cr.Query(uri, Array As String("data1"), "", Null, "")
If c.RowCount > 0 Then
c.Position = 0
Dim phoneNumber As String = c.GetString2(0)
c.Close
Dim cleanNumber As String = ""
For i = 0 To phoneNumber.Length - 1
Dim digit As String = phoneNumber.CharAt(i)
If digit >= "0" And digit <= "9" Then cleanNumber = cleanNumber & digit
Next
If cleanNumber.Length > 8 Then
cleanNumber = cleanNumber.SubString(cleanNumber.Length - 8)
End If
EditText4.Text = cleanNumber
ToastMessageShow("Número: " & cleanNumber, False)
Else
c.Close
End If
Catch
Log(LastException.Message)
End Try
End If
End Sub