0

Is following scenario possible to implement in android app?

  1. Show google calendar to user.
  2. If user is trying to add event fields like title, place etc. are already defined. Only thing he need to do is click 'save' to add event to calendar.

1 Answers1

0

you can use an intent to start the calender event screen

//all version of android
 Intent i = new Intent();

 // mimeType will popup the chooser any  for any implementing application (e.g. the built in calendar or applications such as "Business calendar"
 i.setType("vnd.android.cursor.item/event"); 

 // the time the event should start in millis. This example uses now as the start time and ends in 1 hour
 i.putExtra("beginTime", new Date().getTime()); 
 i.putExtra("endTime", new Date().getTime() + DateUtils.HOUR_IN_MILLIS);

 // the action
 i.setAction(Intent.ACTION_EDIT);
 startActivity(i);

as taken from:how can i open the calendar from my app?

otherwise if you want to push the data without opening the calendar you can try and use the calendar provider check the documantation: http://developer.android.com/guide/topics/providers/calendar-provider.html (examlple in the edit below)

update according to the comment:

do the folowing -

1)use the calendar provider to query for events:

long startMillis = 0; 
long endMillis = 0;     
Calendar beginTime = Calendar.getInstance();
beginTime.set(2012, 9, 14, 7, 30);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2012, 9, 14, 8, 45);
endMillis = endTime.getTimeInMillis();


// Run query
Cursor cur = null;
ContentResolver cr = getContentResolver();
Uri uri = Events.CONTENT_URI;   

String selection = "((" + Events.DTSTART + " >= ?) AND (" 
                        + Events.DTEND + " <= ?))";
String[] selectionArgs = new String[] {startMillis +"", endMillis +""}; 
// Submit the query and get a Cursor object back. 
cur = cr.query(uri, EVENT_PROJECTION, selection, selectionArgs, null);

2)show result using a listView or a gridView use the cursor in a simple adapter

SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
        android.R.layout.simple_list_item_1, 
        cur, 
        new String[] { Events.TITLE, [more fileds you want] }, 
        new int[] { android.R.id.text1 });

ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);

3)under the list have a button for open event once pressed do :

long calID = 3;
long startMillis = 0; 
long endMillis = 0;     
Calendar beginTime = Calendar.getInstance();
beginTime.set(2012, 9, 14, 7, 30);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2012, 9, 14, 8, 45);
endMillis = endTime.getTimeInMillis();
...

ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startMillis);
values.put(Events.DTEND, endMillis);
values.put(Events.TITLE, "Jazzercise");
values.put(Events.DESCRIPTION, "Group workout");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "America/Los_Angeles");
Uri uri = cr.insert(Events.CONTENT_URI, values);

// get the event ID that is the last element in the Uri
long eventID = Long.parseLong(uri.getLastPathSegment());
// 
// ... do something with event ID
//

note that you need the calendar id - you can query for that as well and make the user choose it the first time he opens your app. again its all in the calendar provider documentation

Community
  • 1
  • 1
Gabriel H
  • 1,558
  • 2
  • 14
  • 35
  • What I am trying to achieve is something in the middle. I'd like to show calendar to the user in such manner that user can see other events and then when he decides to add a event, fields like title, description, place will be defined. – piwowarek102 Jan 10 '15 at 22:50