Android 中的日历、触发、Web 服务访问

发布于 2024-10-20 02:21:44 字数 381 浏览 1 评论 0原文

你好,我 我是安卓新手.. 我安装了三星 Galaxy 3 和 android 2.1.. 我想构建一个小部件如下..

1.我想访问手机日历..(谷歌搜索了很多不同的答案,但没有 wokrin..)(jimblackler.net/blog/?p=151 不起作用).. 由于没有可用的公共 API,即使我能够使用谷歌日历(来自网络的日历)也没关系。让我知道哪个更容易实现。我只想读取事件..

2.如何在特定时间触发事件.. 说当 3:00 时它应该调用一个函数.. 是否可以 ?如果是这样,如何

3.我想将两个字符串发送到服务器并接收和其他文本作为结果。这将是最简单的编码方法?有一个 C# Web 服务..?或者只是在服务器上使用接受少量参数的 php 脚本?

多谢。 :)

Hello m
I am new to android..
I have samsung galaxy 3 and android 2.1 installed in it..
I want to build an widget as follows..

1.I want to access calendar of phone.. (googled a lot found diffrent answers but none wokrin..) (jimblackler.net/blog/?p=151 not working)..
since no public api is available it will be ok even if am able to use google calendar(the one from web).. letme know whichever is easier to implement. I just want to read events..

2.How do I trigger events on a specific time.. say when it is 3:00hrs it should call a function..
Is it possible ? if so how

3.I want to send two strings to a server and recieve andother text back as result. which would be the easiest way to code ?? have an c# web service..? or just use a php script on server accepting few parameters?

thanks a lot. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稳稳的幸福 2024-10-27 02:21:44

第一个问题:日历访问:这基于 content://calendar/calendars URI。
首先,确保您的应用程序定义了 android.permission.READ_CALENDAR 权限。

获取日历 ID 和显示名称:

ContentResolver myContentResolver = getContentResolver();

final Cursor cursor = myContentResolver.query(Uri.parse("content://calendar/calendars"),
        (new String[] { "_id", "displayName", "selected" }), null, null, null);

while (cursor.moveToNext()) {

    final String _id = cursor.getString(0);
    final String displayName = cursor.getString(1);
    final Boolean selected = !cursor.getString(2).equals("0");
}

处理特定日历:

Uri.Builder myUriBuilder = Uri.parse("content://calendar/instances/when").buildUpon();
long currentTime = new Date().getTime();
ContentUris.appendId(myUriBuilder , currentTime  - DateUtils.WEEK_IN_MILLIS);
ContentUris.appendId(myUriBuilder, currentTime + DateUtils.WEEK_IN_MILLIS);

Cursor eventCursor = myContentResolver.query(myUriBuilder.build(),
        new String[] { "title", "begin", "end", "allDay"}, "Calendars._id=" + id,
        null, "startDay ASC, startMinute ASC");

while (eventCursor.moveToNext()) {
    // fields:
    // Event title - String - 0
    String eventTitle = eventCursor.getString(0);
    // Event start time - long - 1
    Date startTime = new Date(eventCursor.getLong(1));
    // Event end time - login - 2
    Date endTime = new Date(eventCursor.getLong(2));
    // Is it an All Day Event - String - 3 (0 is false, 1 is true)
    Boolean allDay = !eventCursor.getString(3).equals("0");

}


Second Question: Scheduling Events:
Basically, you should use the AlarmManager class, see the android SDK for details.
Example to set the event 3 hours from now:

 Calendar cal = Calendar.getInstance();
 cal.add(Calendar.HOUR, 3);
 Intent intent = new Intent(this, MyAlarmHandler.class);
 intent.putExtra("alarm_message", "Wake up!");
 int requestCode = 3824723; // this is not currently used by Android.
 PendingIntent pIntent = PendingIntent.getBroadcast(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
 AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
 alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pIntent);


Third Question: Yes, I suggest the PHP approach

First Question: Calendar access: This is based on the content://calendar/calendars URI.
First, make sure your application defines the permission android.permission.READ_CALENDAR.

Get the calendars IDs and display names:

ContentResolver myContentResolver = getContentResolver();

final Cursor cursor = myContentResolver.query(Uri.parse("content://calendar/calendars"),
        (new String[] { "_id", "displayName", "selected" }), null, null, null);

while (cursor.moveToNext()) {

    final String _id = cursor.getString(0);
    final String displayName = cursor.getString(1);
    final Boolean selected = !cursor.getString(2).equals("0");
}

Work on a specific calendar:

Uri.Builder myUriBuilder = Uri.parse("content://calendar/instances/when").buildUpon();
long currentTime = new Date().getTime();
ContentUris.appendId(myUriBuilder , currentTime  - DateUtils.WEEK_IN_MILLIS);
ContentUris.appendId(myUriBuilder, currentTime + DateUtils.WEEK_IN_MILLIS);

Cursor eventCursor = myContentResolver.query(myUriBuilder.build(),
        new String[] { "title", "begin", "end", "allDay"}, "Calendars._id=" + id,
        null, "startDay ASC, startMinute ASC");

while (eventCursor.moveToNext()) {
    // fields:
    // Event title - String - 0
    String eventTitle = eventCursor.getString(0);
    // Event start time - long - 1
    Date startTime = new Date(eventCursor.getLong(1));
    // Event end time - login - 2
    Date endTime = new Date(eventCursor.getLong(2));
    // Is it an All Day Event - String - 3 (0 is false, 1 is true)
    Boolean allDay = !eventCursor.getString(3).equals("0");

}


Second Question: Scheduling Events:
Basically, you should use the AlarmManager class, see the android SDK for details.
Example to set the event 3 hours from now:

 Calendar cal = Calendar.getInstance();
 cal.add(Calendar.HOUR, 3);
 Intent intent = new Intent(this, MyAlarmHandler.class);
 intent.putExtra("alarm_message", "Wake up!");
 int requestCode = 3824723; // this is not currently used by Android.
 PendingIntent pIntent = PendingIntent.getBroadcast(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
 AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
 alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pIntent);


Third Question: Yes, I suggest the PHP approach

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文