The Blog

Write an SMS without sending it on Android 2.2 Froyo

12 Ago 10

I just figured out how to write an sms without sending it really on android froyo 2.2 using the content provider.

I’ll write only the snippet here. Hope it helps

[sourcecode language=”java”]
/**
* writes an sms on the contentprovider
* @param ctx Context
* @param mobNo mobile number
* @param msg text of the message
*/
private final static void storeMessage(Context ctx,String mobNo, String msg) {
ContentValues values = new ContentValues();
values.put("address", mobNo);
values.put("body", msg);
ctx.getContentResolver().insert(Uri.parse("content://sms/sent"), values);
}
[/sourcecode]

Obviously you should set the right permissions on the manifest ( Yes the following are all needed for this task ) :

[sourcecode language=”xml”]
<manifest>
….
….
<uses-permission android:name="android.permission.WRITE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
</manifest>
[/sourcecode]

Comments