# Call contacts app

**URL:** <https://discourse.processing.org/t/call-contacts-app/21170>\
**Category:** Processing for Android\
**Created:** [May 22, 2020, 5:19pm UTC](https://discourse.processing.org/t/call-contacts-app/21170 "2020-05-22T17:19:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bobby54](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bobby54/32/9302_2.png) [@Bobby54](https://discourse.processing.org/u/Bobby54)\
**Post date:** [May 22, 2020, 5:19pm UTC](https://discourse.processing.org/t/call-contacts-app/21170/1 "2020-05-22T17:19:52Z")

</div>

Hi,  
I want to be able to open the on-phone contacts app by clicking on a button in my sketch.  
I am mainly looking for packages to getting the code of the first answer to work.  
[https://stackoverflow.com/questions/5787088/android-launching-contacts-application](https://stackoverflow.com/questions/5787088/android-launching-contacts-application)

I am used to working with the android permissions and already allowed the access to storage and to read and write of contacts(even though I don’t need it).

Thanks in advance

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [May 22, 2020, 6:45pm UTC](https://discourse.processing.org/t/call-contacts-app/21170/2 "2020-05-22T18:45:19Z")

</div>

If you really want to keep it simple; just names and phone numbers.  
Tested with APDE Kitkat 4.4 and Lollipop 5.1 using permission  
READ\_CONTACTS  
You know how to place Android buttons?  
If not see templates on my repo [here](https://github.com/EmmanuelPil/Android-java-code-utilities-widgets-for-Processing-for-Android).

```auto
import android.database.Cursor;
import android.content.ContentResolver;
import android.provider.ContactsContract;
import android.support.v4.app.ActivityCompat;
import android.app.Activity;

Activity act;

void setup() {
  act = this.getActivity(); 
  Cursor phones = act.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
  while (phones.moveToNext()) {
    String contactName=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
    String contactNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
  print(contactName+" ");
  println(contactNumber);
  }
  phones.close();
}

```

---

<div class="post-metadata">

**Author:** ![Bobby54](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bobby54/32/9302_2.png) [@Bobby54](https://discourse.processing.org/u/Bobby54)\
**Post date:** [May 22, 2020, 7:12pm UTC](https://discourse.processing.org/t/call-contacts-app/21170/3 "2020-05-22T19:12:39Z")

</div>

Wow, exactly what I was looking for.  
Thanks

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [May 22, 2020, 7:13pm UTC](https://discourse.processing.org/t/call-contacts-app/21170/4 "2020-05-22T19:13:37Z")

</div>

Do you want to dial the number also?

---

<div class="post-metadata">

**Author:** ![Bobby54](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bobby54/32/9302_2.png) [@Bobby54](https://discourse.processing.org/u/Bobby54)\
**Post date:** [May 22, 2020, 7:15pm UTC](https://discourse.processing.org/t/call-contacts-app/21170/5 "2020-05-22T19:15:57Z")

</div>

Yes, I want to be able to dial a number and send sms.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [May 22, 2020, 7:20pm UTC](https://discourse.processing.org/t/call-contacts-app/21170/6 "2020-05-22T19:20:45Z")

</div>

Are you going to implement all this gigantic amount of code?

```auto
import android.database.Cursor;
import android.content.Intent;
import android.net.Uri;

void setup() {
  Uri number = Uri.parse("tel:123456789");
  Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
  startActivity(callIntent);
}

```

---

<div class="post-metadata">

**Author:** ![Bobby54](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bobby54/32/9302_2.png) [@Bobby54](https://discourse.processing.org/u/Bobby54)\
**Post date:** [May 22, 2020, 7:28pm UTC](https://discourse.processing.org/t/call-contacts-app/21170/7 "2020-05-22T19:28:52Z")

</div>

I started copy-pasting your code and then got this error:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/ca0383c7e956ee41452dfff599b5cfb2e0010a61.png)  
Do you know how to fix this?

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [May 22, 2020, 7:31pm UTC](https://discourse.processing.org/t/call-contacts-app/21170/8 "2020-05-22T19:31:09Z")

</div>

And if you comment this import?  
What android version are you using?

---

<div class="post-metadata">

**Author:** ![Bobby54](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bobby54/32/9302_2.png) [@Bobby54](https://discourse.processing.org/u/Bobby54)\
**Post date:** [May 22, 2020, 7:36pm UTC](https://discourse.processing.org/t/call-contacts-app/21170/9 "2020-05-22T19:36:46Z")

</div>

commented the error and ran the code, works fine, thanks.  
Android version is 6.0.1, so rather old

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [May 22, 2020, 7:47pm UTC](https://discourse.processing.org/t/call-contacts-app/21170/10 "2020-05-22T19:47:57Z")

</div>

Here is how to send a msg.  
I, unfortunately, could not test it because I get the warning “You have no credits.” 😃  
If you have some time please cheque my templates on repo for errors.  
Needs permission SEND\_SMS

```auto
import android.database.Cursor;
import android.content.Intent;
import android.net.Uri;
import android.telephony.SmsManager;

String phone_number = "81984763036";
String send_message = "Happy birthday";

void setup() {
  try {
    SmsManager sms = SmsManager.getDefault(); 
    sms.sendTextMessage(phone_number, null, send_message, null, null);
  } 
  catch (Exception e) {
    println ("Sms not Send");
    e.printStackTrace();
  }
}

```

---

<div class="post-metadata">

**Author:** ![Bobby54](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bobby54/32/9302_2.png) [@Bobby54](https://discourse.processing.org/u/Bobby54)\
**Post date:** [May 22, 2020, 8:15pm UTC](https://discourse.processing.org/t/call-contacts-app/21170/11 "2020-05-22T20:15:35Z")

</div>

Thanks again for your help.

> [@noel](#):
>
> If you have some time please cheque my templates on repo for errors

I will but I’m probably not gonna be a lot of help.
