How can we insert date in content://sms/inbox.
i m using this code
ContentValues sms = new ContentValues();
sms.put("date", long date);
objContext.getContentResolver().insert( Uri.parse("content://sms/inbox"),sms);
plz give me any solution.
Thanx
khan
Use this:
sms.put("date", String.valueOf(System.currentTimeMillis()));
Related
I'm trying to insert events in to a calendar i created. I'm using the following code to do so... it's taken from google's documentation on CalendarProvider.
The problem is that no matter what values i put in DTSTART or DTEND the event is always created as a single day event and the date is the current date.
I've also tried to use Intent(Intent.ACTION_EDIT) with .putExtra for the dates... but sadly this doesn't help as well... neither the dates are set nor it gives me to modify them in the edit intent.
Any Idea what might be causing this behavior?
ContentValues event = new ContentValues();
event.put(Events.CALENDAR_ID, e.getCalendarId());
event.put(Events.TITLE, e.getTitle());
event.put(Events.DESCRIPTION, e.getDescription());
event.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getDisplayName());
event.put(Events.EVENT_END_TIMEZONE, TimeZone.getDefault().getDisplayName());
event.put(Events.GUESTS_CAN_MODIFY, 1);
event.put(Events.IS_ORGANIZER, 1);
event.put(Events.DTSTART, e.getDateStart());
event.put(Events.DTEND, e.getDateEnd());
event.put(Events.ALL_DAY, 1);
event.putNull(Events.DURATION);
event.putNull(Events.RRULE);
event.putNull(Events.RDATE);
Uri eventUri = context.getContentResolver().insert(Events.CONTENT_URI, event);
int eventID = Integer.parseInt(eventUri.getLastPathSegment());
I am trying to do this by writing this code
ContentValues values = new ContentValues();
values.put(Sms.TYPE, Sms.MESSAGE_TYPE_SENT);
context.getContentResolver().update(Uri.parse("content://sms"), values, Sms.THREAD_ID+"=? AND "+Sms._ID+"=?", new String[]{thread_id,_id);
but no luck! this is not working.
so, help would be appericiated.
I'm just getting up to speed on Android, and I want to send calendar event to others from mobile. Same as whatsapp sending contacts. For sending Contact in chat (XMPP) I've used vCard. So for sending calendar event in chat what should I use?
I have searched a lot. But can't find something fruitful.
Please suggest the library or code snippet for sending calendar event in XMPP.
Thanks in advance.
You may refer to iCal Import Export allows you to import iCalender files to your calender without using google synchronization services.
Using this you can import all calendar events to iCalendar files and also export those events back to calendar. Using Calendar Provider you can fetch all calendar data, but requires android API level 14 or above while using iCal Import Export you can fetch all calendar data for lower API levels too.
manifest
<uses-permission android:name="android.permission.READ_CALENDAR" />
Code:
Cursor cursor = cr.query(Uri.parse("content://calendar/calendars"), new String[]{ "_id", "displayname" }, null, null, null);
cursor.moveToFirst();
String[] CalNames = new String[cursor.getCount()];
int[] CalIds = new int[cursor.getCount()];
for (int i = 0; i < CalNames.length; i++) {
CalIds[i] = cursor.getInt(0);
CalNames[i] = cursor.getString(1);
cursor.moveToNext();
}
cursor.close();
Fetching all events, and particular event is done by specifying range
ContentResolver contentResolver = getContentResolver();
Uri.Builder builder = Uri.parse(getCalendarUriBase() + "/instances/when").buildUpon();
long now = new Date().getTime();
ContentUris.appendId(builder, now - DateUtils.MILLIS_PER_DAY*10000);
ContentUris.appendId(builder, now + DateUtils.MILLIS_PER_DAY * 10000);
and then let's say you wish to log events ID from calendar with ID = 1
Cursor eventCursor = contentResolver.query(builder.build(),
new String[] { "event_id"}, "Calendars._id=" + 1,
null, "startDay ASC, startMinute ASC");
// For a full list of available columns see http://tinyurl.com/yfbg76w
while (eventCursor.moveToNext()) {
String uid2 = eventCursor.getString(0);
Log.v("eventID : ", uid2);
}
Now display this event in Listview select one of this for send as a text messsage and on receiver side :
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", cal.getTimeInMillis());
intent.putExtra("allDay", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
intent.putExtra("title", HERE MSG WHICH YOU RECEIVE);
startActivity(intent);
There is no library AFAIK and it's really just a matter of retrieving the calender event and transforming it's data into XML. Unfortunately there is also no XEP on how calendar events should be represented in XMPP/XML so you have to come up with your own representation.
iCalendar/vCalendar is the calendar file format similar to vCard
You can add new field in vcard that save calender info example
VCard vCard = new VCard();
vCard.setField("calender","calender info");
calender info should be a sting, it can be a json format string.
user who receives it can load your vcard and use method
vCard.load(connection, Jid);
String string=vCard.getField("calender");
You really don't need any specific library for that purpose.
You can check out Calendar Provider
They have an awesome example on it too!
Be sure to use these permissions in your manifest.xml
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
And if you wish to send contacts then check this out Android: How to import contact from phone?
Vote this up if it helped you! I really need it. :)
Hi stackoverflow I'm trying to develop an application to add SMS to prrogrammatically, I'm using the following code to add SMS
private void addSMS()
{
Uri uri = Uri.parse("content://sms/");
ContentValues cv2 = new ContentValues();
cv2.put("address", "+91956322222");
cv2.put("date", "1309632433677");
cv2.put("read", 1);
cv2.put("type", 2);
cv2.put("body", "Hey");
getContentResolver().insert(uri, cv2);
cv2.clear();
}
Permissions :
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
Problem is the Time of the message, it's displaying the time we added the message, but not the date we have passed in the list of messages, but when I open the message we added then the time will be correct as our input, please help me to solve this riddle.
Thanks.
This is a known problem I think. Try to add this line in the end:
getContentResolver().delete(Uri.parse("content://sms/conversations/-1"), null, null);
If you want more explanation you should check this out!
Here is the working code, Thanks to #Amulya Khare
private void addSMS()
{
Uri uri = Uri.parse("content://sms/");
ContentValues cv2 = new ContentValues();
cv2.put("address", "+91956322222");
cv2.put("date", "1309632433677");
cv2.put("read", 1);
cv2.put("type", 2);
cv2.put("body", "Hey");
getContentResolver().insert(uri, cv2);
/** This is very important line to solve the problem */
getContentResolver().delete(Uri.parse("content://sms/conversations/-1"), null, null);
cv2.clear();
}
Please follow the link to get more information Android programatically inserted SMS have incorrect timestamp in Messaging apps
Is possible to start default people/contact activity and pass structured data like
separated first name and last name, phone type, city, postal code and similar data.
I use following similar code:
Intent addContactIntent = new Intent(Intent.ACTION_INSERT);
addContactIntent.setType(ContactsContract.Contacts.CONTENT_TYPE);
addContactIntent.putExtra(ContactsContract.Intents.Insert.POSTAL, "abc 2343");
startActivity(addContactIntent );
This works fine but I can't specify which is for example postal code, and what is city or place.
I found samples like this here but I cant start add new contact intent before, so user can't edit something before he saves contact. Code immediately saves the contact without user interaction.
Any help would be appreciable.
As for your information you can use ContactsContract.Intents.Insert.DATA ,which is designed to insert multiple data items.Like city,state etc for the address field.But the real problem is it in not available prior to API 11.
Here is how its work.
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
//Email
ContentValues row1 = new ContentValues();
row1.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
row1.put(Email.ADDRESS, "ADDRESSme");
data.add(row1);
//Website
ContentValues row2 = new ContentValues();
row2.put(Data.MIMETYPE, Website.CONTENT_ITEM_TYPE);
row2.put(Website.URL, "URLme");
data.add(row2);
//Address
ContentValues row4 = new ContentValues();
row4.put(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE);
row4.put(StructuredPostal.CITY, "CityMe");//Pre populating city
row4.put(StructuredPostal.COUNTRY, "COUNTRYme");//Pre populating country
row4.put(StructuredPostal.STREET, "STREETme");////Pre populating street
row4.put(StructuredPostal.POSTCODE, "POSTCODEme");//
data.add(row4);
Intent i = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
i.putParcelableArrayListExtra(Insert.DATA, data);