android - Restore Sms : create thread if not exists -


i'm creating android app able restore sms webservice.

i insert sms in existing conversations , works fine. but, if conversation not exists, sms restored don't appears in sms app...

i think have create new thread (a new conversation).

contentvalues initialvalues; initialvalues = new contentvalues(); initialvalues.put("_id", talk.getid()); initialvalues.put("recipient_ids", talk.getcontact().getid()); context.getcontentresolver().insert(uri.parse("content://mms-sms/conversations?simple=true"), initialvalues); 

app crashes error :

mmssmsprovider not support deletes, inserts, or updates uri.content://mms-sms/conversations?simple=true

this example give threadid, create new id if recipient doesn't exist otherwise return existing threadid:

public static long getthreadid(context context, string phonenumber) {     uri threadiduri = uri.parse("content://mms-sms/threadid");     uri.builder uribuilder = threadiduri.buildupon();     uribuilder.appendqueryparameter("recipient", phonenumber);     uri uri = uribuilder.build();      cursor cursor = context.getcontentresolver().query(uri,          new string[]{"_id"} /* projection */,          null /* selection */,          null /* selectionargs */,          null /* order */);     if (cursor != null) {         try {             if (cursor.movetofirst()) {                 return cursor.getlong(0);             }         } {             cursor.close();         }     }     return 0; } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -