SMS to Contacts.People.PRIMARY_PHONE_ID

Put your problem here if it does not fit any of the other categories.

SMS to Contacts.People.PRIMARY_PHONE_ID

Postby juxmw » Fri Jan 08, 2010 7:27 pm


My application is storing a Contacts.People.PRIMARY_PHONE_ID as foreign key in it's table to remember the relation to a phone contact id.

A ListView is responsible for displaying the data from within the cursor (resultset).
So far so easy, but I want to be able to send a SMS to this contact from a ContextMenu using Android's standard SMS tool.

I assume it is the easiest way to use a "implicit Intent" - but how to pass the user info (adress? id? name? number?) to the sms app? This is what I found out so far:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  2.                 Intent smsIntent = new Intent(Intent.ACTION_VIEW);
  4.                 smsIntent.putExtra("address", PHONE_NR);
  6.                 smsIntent.setType("");
  8.                 startActivity(smsIntent);
Parsed in 0.013 seconds, using GeSHi

But do I really need to get the phone number from the address book related to this id before? Or is there a more simple way to achieve this? Like just passing the id or access the phone number in an easier way than using a ContentResolver.

BR and thanks for helping
Posts: 2
Joined: Fri Jan 08, 2010 7:13 pm


Postby juxmw » Sat Jan 09, 2010 12:52 pm

ok, I found out that I HAVE to use a ContentResolver and there is no way to pass a unique UserID to the SMS app and let it do it's job - so my prev. post may be a little bit brainless (but I was hoping :) )

What I have so far is:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  2.         // get URI for Contact ID #1 just for testing
  3.         Cursor c = getContentResolver().query(People.CONTENT_URI,
  4.                                                                   new String[]{People.NUMBER},
  5.                                                                   "People._ID" + " = " + "1",
  6.                                                                   null,
  7.                                                                   Phones.ISPRIMARY + " DESC"
  8.         );
  10.         try {
  11.             if (c.moveToFirst()) {
  12.                 Log.w("1", "GOT NUMBER: " + c.getString(0));
  13.             } else {
  14.                 Log.w("1", "noooooooooooooooooooo");
  15.             }
  17.         } finally {
  18.             c.close();
  19.         }
Parsed in 0.012 seconds, using GeSHi

Now what is even more confusing to me is:

  • I had read a lot until I found out the URL (ContentProvider etc) - is there a easy way to gather this information.
    If I would need to get - lets say - a calendar entry. Where can I get info about the responsible ContentProvider, it's class or even it's DB structure. What IS the responsible Provider?
  • I know - the Provider should encapsulate all data queries - but it toke me some time to figure out the correct query parameters (it was possible because logcat showed me that the underlying SQL failed - so I was able to adopt the parameter).
    Again - is there any RELIABLE documentation for ContenProviders query parameters that also shows API changes (see next question).
  • The API changed a lot with cupcake Contacts.People.Phones is deprecated now - I assume the "old" code may stop working in later releases?

In general - until now it was quit fun to develop Android - this was the the first time I thought ... "WTF". Maybe I don't understand the underlying concept - also possible :)

Posts: 2
Joined: Fri Jan 08, 2010 7:13 pm


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 8 guests