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

Hi

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
  1.  
  2.                 Intent smsIntent = new Intent(Intent.ACTION_VIEW);
  3.  
  4.                 smsIntent.putExtra("address", PHONE_NR);
  5.  
  6.                 smsIntent.setType("vnd.android-dir/mms-sms");
  7.  
  8.                 startActivity(smsIntent);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


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
Juxm
juxmw
Freshman
Freshman
 
Posts: 2
Joined: Fri Jan 08, 2010 7:13 pm

Top

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
  1.        
  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.         );
  9.  
  10.         try {
  11.             if (c.moveToFirst()) {
  12.                 Log.w("1", "GOT NUMBER: " + c.getString(0));
  13.             } else {
  14.                 Log.w("1", "noooooooooooooooooooo");
  15.             }
  16.            
  17.         } finally {
  18.             c.close();
  19.         }
  20.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


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 :)

BR
Juergen
juxmw
Freshman
Freshman
 
Posts: 2
Joined: Fri Jan 08, 2010 7:13 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot], Google Feedfetcher and 15 guests