从Android应用程序导出到谷歌日历应用程序的文件

时间:2012-06-13 17:21:40

标签: android android-intent export icalendar

我搜索了这个主题并找到了这两个网站:

Get content uri from file path in android

http://developer.android.com/training/basics/intents/sending.html

我想要做的是从Android应用中导出一个文件,然后将日历导入到Google日历应用中。因此,如果我点击一个按钮,我的应用程序应该发送一个意图,Android应用程序选择器应该出现。然后我希望能够选择谷歌日历并让日历导入ical文件。

到目前为止,这是我的代码:

Uri uri = Uri.fromFile(new File(fileName));
//Uri uri = Uri.parse(fileName);
Intent calendarIntent = new Intent(Intent.ACTION_VIEW, uri);
final Intent chooser = Intent.createChooser(calendarIntent, "choose");
...
startActivity(chooser);

我可以使用fileName打开文件,所以这应该不是问题(fileName只包含类似“file.ics”的内容)。如果我运行此代码,Android应用程序选择器说没有应用程序能够处理此操作。我在Eclipse中使用Google API level 7作为库,我使用Android 4.04部署到Galaxy Nexus设备进行测试。我无法弄清楚我做错了什么。有什么建议?在此先感谢您的帮助!

编辑:

以下代码显示了可供选择的应用列表:

Uri uri = Uri.parse(fileName);
Intent calendarIntent = new Intent(Intent.ACTION_SEND, uri);
calendarIntent.setType("text/calendar");
final Intent chooser = Intent.createChooser(calendarIntent, "choose");

但日历不在此列表中。所以我在手机上下载了文件并尝试打开它。即使这样,只有文本编辑器,但没有日历应用程序出现。所以在我看来,不可能将ical文件导入谷歌日历应用程序。我很高兴被证明是错的......

0 个答案:

没有答案