How can I send fake sms to myself without mobile network usage?

AdemC picture AdemC · May 10, 2011 · Viewed 7.9k times · Source

I want to show some information as an sms in my application. But SmsManager and BroadcastReciever can not create sms and notify on phone itself.

How can I send a fake sms to myself programmatically? Any ideas, workarounds or any class for research... ?

Thanks.

Answer

Mertuarez picture Mertuarez · Nov 29, 2011

PROOF OF CONCEPT

Call SMS list

Intent intent = new Intent("android.intent.action.MAIN");
        intent.setComponent(
            new ComponentName("com.android.mms","com.android.mms.ui.ConversationList"));
        startActivity(intent);

READ SMS

cursor c= getContentResolver().query(uri, null, null ,null,null); 
        startManagingCursor(c);
        c.moveToFirst();  

            String body = c.getString(c.getColumnIndexOrThrow("body")).toString();
            String number = c.getString(c.getColumnIndexOrThrow("address")).toString();

        c.close(); 

        Toast.makeText(getApplicationContext(), number, Toast.LENGTH_LONG).show();

Write SMS

ContentValues values = new ContentValues();
        values.put("address", "SENDER");
        values.put("body", "foo bar");
        getContentResolver().insert(Uri.parse("content://sms/inbox"), values);

MANIFEST

<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>

ISSUE There is no event after that therefore android doesnt known if there is some new message.