Reputation: 11
I have been trying to do this using content://sms/sim URI. But i can just access the data base, but not add to it. I actually want to implement 'copy to sim' functionality in my application.
This is my code snippet:
ArrayList listName=new ArrayList();
ArrayList listContactId=new ArrayList();
ArrayList listMobileNo=new ArrayList();
ArrayList listEmail=new ArrayList();
Uri simUri = Uri.parse("content://sms/sim");
Cursor cursorSim = this.getContentResolver().query(simUri, null, null,null, null);
String[] coloumnName=new String[cursorSim.getColumnCount()];
for(int i=0;i<cursorSim.getColumnCount();i++)
{
coloumnName[i]= cursorSim.getColumnName(i);
Log.i("Coulmn name -------!!!!!----------------",coloumnName[i]);
}
while (cursorSim.moveToNext()) {
listName. add(cursorSim.getString(cursorSim.getColumnIndex("name")));
listContactId. add(cursorSim.getString(cursorSim.getColumnIndex("_id")));
listMobileNo. add(cursorSim.getString(cursorSim.getColumnIndex("number")));
listEmail.add(cursorSim.getString(cursorSim.getColumnIndex("emails")));
}
This just allows me to read messages.
When i try to insert data.
Code snippet:
//Insert ContentValues values = new ContentValues();
// values.put("name", "One");
values.put("address", "1111111111"); values.put("body", "Its a great day. Thats is been expected since i was born"); values.put("date", "1312434417006"); Uri newRowUri = getContentResolver().insert(simUri , values); 09-02 17:35:07.209: ERROR/SmsProvider(1476): Invalid request: content://sms/icc
I have given necessary permissions in my manifest file. Can anyone suggest me how to do it. I even want to know whether this can be done, are there enough permissions to do this also.
Thanks Vaishnavi
Upvotes: 1
Views: 1981
Reputation: 10098
to read an sms from the phone you can use the regular api
Cursor cursor = context.getContentResolver().query(
SMS_INBOX_CONTENT_URI,
new String[] { "_id", "thread_id", "address", "person", "date", "body" },
WHERE_CONDITION,
null,
SORT_ORDER);
now iterate through the cursor & get the message
you can use the SmsContentProvider to save the message in another folder.. (say the sim card)
ContentValues values = new ContentValues();
values.put("address", "123456789");
values.put("body", "foo bar");
getContentResolver().insert(Uri.parse("content://sms/sent"), values);
ofcourse there are some loose ends which needs to be tied up..
its important to remind you to be careful while using content providers check this link
Upvotes: 0