I’ve created one application that is inserting messages programmatically. In that application running successfully.
It’ll inserted the message whatever given in record. After, you’ll not able to see your inserted message in your messages where device or emulator. Check out that.
I don’t know why this is happening. You’ll able to see your message when, you stopped the messaging in your task manager. After, you can see your inserted message.
What am missing in that code.
Any help appreciated? Best Regards – SPK
The code
Activity:
public class SMS extends Activity
{
Button btnSendSMS;
EditText txtPhoneNo;
EditText txtMessage;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
final insert i = new insert(this);
btnSendSMS.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
i.method_inser();
Toast.makeText(getApplicationContext(), "Inserted", Toast.LENGTH_SHORT).show();
}
});
}
}
Class insert:
public class insert
{
Context ctx,context;
ContentResolver cr;
public insert(Context context)
{
this.context = context;
cr = context.getContentResolver();
}
public void method_inser()
{
Uri smsuri = Uri.parse("content://sms/");
ContentValues iv = new ContentValues();
String[] final_result = {"1","1","15555215556","3","1320753694842","0","1","-1","1","0","null","Gingerbread","null","0","0","1"};
iv.put("_id", final_result[0]);
iv.put("thread_id", final_result[1]);
iv.put("address", final_result[2]);
iv.put("person", final_result[3]);
iv.put("date", final_result[4]);
iv.put("protocol", final_result[5]);
iv.put("read", final_result[6]);
iv.put("status", final_result[7]);
iv.put("type", final_result[8]);
iv.put("reply_path_present", final_result[9]);
iv.put("subject", final_result[10]);
iv.put("body", final_result[11]);
iv.put("service_center", final_result[12]);
iv.put("locked", final_result[13]);
iv.put("error_code", final_result[14]);
iv.put("seen", final_result[15]);
cr.insert(smsuri, iv);
}
}
_idandthread_idareprimary keyand you are trying to insert fix value all the time so it will work only onceAlso remove two fields
error_codeandseenbecausethere are no any column in a sms tableAlso you have to add following permissions in manifest
After inserting new message in inbox you have to notify changed using content resolver
Use this code to notify change