Android implements a method for writing sent SMS messages to the SMS database

  • 2020-06-07 05:15:44
  • OfStack

SMS is a common function of mobile phones. This paper describes the method of Android to write SMS messages to SMS database in the form of an example. To share with you for your reference. The details are as follows:

In general, after sending an SMS message, you need to write the sent SMS message to the SMS database. The SMS database has multiple Uri, of which the Uri sent is content://sms/sent.

The specific function code is as follows:


//  Write the message to the database 
public void writeMsg(){
   
  try{
    ContentValues values = new ContentValues();
    //  Send time 
    values.put("date", System.currentTimeMillis());
    //  Reading state       
    values.put("read", 0);
    //  Type: 1 To collect, 2 For the hair       
    values.put("type", 2);
    //  Send the number       
    values.put("address",smsWidget.str_number);
    //  Send content      
    values.put("body", content);
    //  Insert SMS library  
    getContentResolver().insert(Uri.parse("content://sms/sent"), values);      
  }catch (Exception e) { 
        Log.d("Exception", e.getMessage()); 
  }
}

Define a new ContentValues, add put to the message, and then getContentResolver().insert ().

I hope this article has been helpful for your Android programming.


Related articles: