9
   The code Written below works for me

                Intent intent = new Intent(Intent.ACTION_EDIT);
                intent.setType("vnd.android.cursor.item/event");
                intent.putExtra("title", "Hi this me");
                intent.putExtra("description", "Some description");
                intent.putExtra("beginTime", eventStartInMillis);
                intent.putExtra("endTime", eventEndInMillis);
                startActivityForResult(intent, 1);

my question is that i can't back the android calendar data in OnActivityResult, i don't know why please help me for this issue.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == 1) {

     if(resultCode == RESULT_OK){

      String result=data.getStringExtra("title");

}


And i am getting data.getExtras() is null !!!!!
miten joshi
  • 185
  • 1
  • 8

5 Answers5

1

It s Because Result code always Return 0 In android calendar Activity result of Calendar implicit intent try using RESULT_CANCEL in onActivity result

public void onActivityResult(int reqCode, int resultCode, Intent data) {

super.onActivityResult(reqCode, resultCode, data);

switch (reqCode) {

if (resultCode == Activity.RESULT_CANCEL)

And You Have to just Check out Next Event ID it will working Hope it will Help to you..

Govind

Community
  • 1
  • 1
1

If you look at the official documentation: http://developer.android.com/reference/android/app/Activity.html#setResult(int, android.content.Intent) you will see that the Intent you get in onActivityResult() is actually dependent on the Activity you are calling. More specifically it depends on whether the called Activity uses setResult(int, android.content.Intent) with an Intent with extras or not.

From a quick internet search it seems that the code you are using is for adding an event in the Calendar, but that does not neccessary mean that you will get the event data back from the Calendar app. Perhups you have to query the Calendar afterwards to get them.

As for the Contacts app, it specifically states so in the Contacts Provider Guide, that you can get the contact data in onActivityResult() if you use startActivityForResult. In the Calendar Provider Guide there is no such statement, so it is probably not supported.

Paris
  • 367
  • 3
  • 13
-1

You can use this code:

public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
 if (resultCode == Activity.RESULT_OK) {
        Bundle extras = data.getExtras();
        String title=extras.getString("title");
        String description=extras.getString("description");
        String beginTime=extras.getString("beginTime");
        String endTime=extras.getString("endTime");
Ricky Khatri
  • 952
  • 2
  • 16
  • 42
-1

The problem is you are putting the data to intent directly and retrieving it through Bundle.

Try this:

Crete a bundle object like this:

Intent i = new Intent("yourFullyQualifiedClassName");

 Bundle extras = new Bundle();
 extras.putString("title", "Hi this me");
 extras.putString("description", "Some description");
 i.putExtras(extras);

Then retrieve the data from the bundle like this:

Bundle bundle = data.getExtras();

bundle.getString("title");

Hope this solves your problem.

Kanth
  • 6,681
  • 3
  • 29
  • 41
  • But Bundle bundle = getIntent().getExtras(); is returning null – miten joshi Dec 06 '12 at 07:30
  • @mitenjoshi I gave you somewhat generalized answer. Replace getIntent() with "data" as the intent is available directly as data in your method. – Kanth Dec 06 '12 at 07:33
  • Yes i implemented with that but also still the same – miten joshi Dec 06 '12 at 07:38
  • 1
    Show me your full code then . Edit your question or share the links that show your code. How could you get into if condition in switch statement without case? Strange. – Kanth Dec 06 '12 at 07:41
-1

It is because you are passing the data to the activity that you started (Activity B) by startActivityForResult from Activity A. onActivityResult() will only get the data passed by Activity B and not by Activity A.

Here's a nice tutorial about android intents.

http://www.vogella.com/articles/AndroidIntent/article.html

and this site too

http://saigeethamn.blogspot.jp/2009/08/android-developer-tutorial-for_31.html

artsylar
  • 2,648
  • 4
  • 34
  • 51
  • but i got the contactdata using the same startactivityforresult but can't get calendar data that i dont know!! – miten joshi Dec 06 '12 at 09:06
  • if (resultCode == Activity.RESULT_OK) { Uri contactData = data.getData(); Cursor c = managedQuery(contactData, null, null, null, null); if (c.moveToFirst()) { String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); System.out.println("CONTACT NAME IS" + name); this code give the contact data – miten joshi Dec 06 '12 at 09:15