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);

我的问题是我无法在 OnActivityResult 中备份 android 日历数据,我不知道为什么请帮我解决这个问题。

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 !!!!!
4

5 回答 5

1

如果您查看官方文档: http: //developer.android.com/reference/android/app/Activity.html#setResult(int, android.content.Intent) 您会看到您在 onActivityResult() 中获得的 Intent实际上取决于您正在调用的活动。更具体地说,它取决于被调用的 Activity 是否使用带有附加功能的 Intent 的 setResult(int, android.content.Intent)。

通过快速的互联网搜索,您使用的代码似乎是用于在日历中添加事件,但这并不意味着您将从日历应用程序中获取事件数据。Perhups 你必须在之后查询日历才能得到它们。

至于 Contacts 应用程序,它在Contacts Provider Guide中明确说明,如果您使用 startActivityForResult,您可以在 onActivityResult() 中获取联系人数据。在 Calendar Provider Guide 中没有这样的声明,因此它可能不受支持。

于 2014-01-09T14:23:03.017 回答
1

这是因为结果代码总是返回 0 在日历隐式意图的 android 日历活动结果中尝试在 onActivity 结果中使用 RESULT_CANCEL

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

super.onActivityResult(reqCode, resultCode, data);

开关(reqCode){

if (resultCode == Activity.RESULT_CANCEL)

而且您必须检查下一个事件 ID它会起作用希望它会对您有所帮助..

戈文德

于 2013-05-09T07:27:42.250 回答
-1

问题是您将数据直接放入意图并通过 Bundle 检索它。

尝试这个:

像这样创建一个捆绑对象:

Intent i = new Intent("yourFullyQualifiedClassName");

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

然后从包中检索数据,如下所示:

Bundle bundle = data.getExtras();

bundle.getString("title");

希望这能解决您的问题。

于 2012-12-06T07:08:55.003 回答
-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

于 2012-12-06T08:53:58.713 回答
-1

您可以使用以下代码:

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");
于 2012-12-06T06:59:21.370 回答