Hi All,

In my application I have tried to get thread id using following code.

public static long getThreadIdFromAddress(ContentResolver resolver,
                        String address)
        {
                if (address == null)
                {
                        return 0;
                }
                // Content URIs for SMS app, these may change in future SDK
                Uri threadIdContentUri = Uri.withAppendedPath(Uri
                                .parse("content://mms-sms/"), "threadID");
                String smsId = "_id";
                String threadRecipientQuery = "recipient";
                Uri.Builder uriBuilder = threadIdContentUri.buildUpon();
                uriBuilder.appendQueryParameter(threadRecipientQuery, address);
                long threadId = 0;
                Cursor cursor = resolver.query(uriBuilder.build(),
                                new String[] { smsId }, null, null, null);
                if (cursor != null)
                {
                        try
                        {
                                if (cursor.getCount() > 0)
                                {
                                        cursor.moveToFirst();
                                        for (int i = 0; i < cursor.getCount(); 
i++)
                                        {
                                                threadId = cursor.getLong(i);
                                        }
                                }
                        }
                        finally
                        {
                                cursor.close();
                                cursor = null;
                        }
                }
                return threadId;
        }

This is creating new thread id if its not exits in the sms-mms
database.

I have refered Threads class code from 
http://hi-android.info/src/android/provider/Telephony.java.html.
This clearly indicates that new thread will get generated if it does
not exists.

In our application we are trying to get all conversations/messages for
the contacts used. We are fetching conversations/message data on the
basis of threadId which we are getting from above method call. Now
even if a particular contact does not have any message thread
available in message store, an empty message is getting generated. And
in native message application the newly generated message thread with
subject line as "(No subject)" is getting displayed.

I want to avoid this. If there is no message for a particular contact
I want to get thread id as "null" or "0". Do you know how can I
achieve this?

Or do you have any other suggetion to avoid above mentioned scenario?

Note: The device I have used is HTC-Nexus One. And the android version
used is 2.2.1.

Thanks,
Madhavi




-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to