I would handle sms with my app.
I use this code to insert the message into provider android:
ContentValues values = new ContentValues();
values.put("address", phoneNumber);
values.put("date", System.currentTimeMillis());
values.put("body", text);
values.put("type", 1);
values.put("read", 1);
if (Build.VERSION.SDK_INT >= 19)
values.put(Inbox.DATE_SENT, System.currentTimeMillis());
context.getContentResolver().insert(Uri.parse("content://sms"), values);
The message is insert correctly but when i see it i reply an error.
The date of receipt is correct, but the date of dispatch is not correct (it's set to 1 January 1970).
How can i set it?
Thank you!
Related
I want tosave operator Name also but i can't find any appropriate tag for that Any body please help me on This.
ContentValues values = new ContentValues();
values.put("address", originatingAddress);
values.put("body", sampleContent);
values.put("date", timeStamp);
context.getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
For getting operator name you can use:
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE));
String OperatorName = manager.getNetworkOperatorName();
and then use it in your code as you want OR like below:
ContentValues values = new ContentValues();
values.put("address", originatingAddress);
values.put("body", sampleContent);
values.put("date", timeStamp);
values.put("body", OperatorName);
context.getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
I need to receive sms from this a particular number, encrypt it and later sent in the inbox. This way my message is protected from reading by anyone else who handles my phone.
Try something like this
ContentValues values = new ContentValues();
values.put("address", "123456789");
values.put("body", "foo bar");
getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
I hope this helps
i programmed a fake sms sender and have problem to show sms notification after inserted,
i use this code to insert sms :
ContentValues values = new ContentValues();
values.put("address", "123456");
values.put("body", "Test !");
values.put("status", -1);
values.put("date", String.valueOf(System.currentTimeMillis()));
getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
and tested this code, but email app return force close :
Intent a = new Intent("android.provider.Telephony.SMS_RECEIVED");
byte[] by =(byte[])(SmsMessage.getSubmitPdu("123456", "123456", "Test !", false).encodedMessage);
Object[] vrs = {by};
a.putExtra("pdus",vrs);
sendBroadcast(a);
I am able to getting all messages with its data, type ,address,status etc. but I am not able restore these messages.I tried the following way. It inserts correctly but it shows current date not date of message recieved or send.Please help me how can I restore messages.
ContentValues values = new ContentValues();
values.put("address", "9878782944");
values.put("body", "foo bar");
values.put("date", "1322039220502");
values.put("type", "1");
values.put("status", "-1");
values.put("read", "1");
values.put("protocol", "0");
getContentResolver().insert(Uri.parse("content://sms"), values);
Well I am using the code below to restore SMS and in the "date" field I am giving Date in "yyyy-MM-dd kk:mm" format instead of long in millis, and it is working fine for me.
ContentValues values = new ContentValues();
values.put("address", numberFile);
values.put("body", bodyFile);
values.put("date", dateFile);
values.put("read", readStatusFile);
getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
Also I am telling the insert function about the folder of SMS e.g. inbox. See if this can help you.
Convert Date in below given format. Android stores data in Milliseconds. So convert it before passing date to value.
ContentValues values = new ContentValues();
values.put("address", "8872743939");
values.put("body", "My Name is Kamal");
values.put("read", 1);
java.util.Date date = new java.util.Date(Message.getinstance().getDate());
Long Date = date.getTime();
values.put("date", Date.toString());
context.getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
My app sends an sms and I would like to update the phone sent box
as if the sms was sent bu the user.
How can this be done ?
You need to add this lines after smsManager.sendTextMessage(number, null,desc, sentPI, deliveredPI);:
ContentValues values = new ContentValues();
values.put("address", number);
values.put("body", desc);
getApplicationContext().getContentResolver().insert(Uri.parse("content://sms/sent"), values);