您的位置:首页 > 移动开发 > Android开发

android developer tiny share-20160816

2016-08-16 10:36 447 查看
今天讲创建倒计时、显示所有闹钟列表、创建日历事件这三个intent,如下:

1.Create a timer

To create a countdown timer, use the ACTION_SET_TIMER action and specify timer details such as the duration using extras defined below.

Note: This intent was added in Android 4.4 (API level 19).

Action

    ACTION_SET_TIMER
Data URI

    None
MIME Type

    None
Extras

    EXTRA_LENGTH

        The length of the timer in seconds.

    EXTRA_MESSAGE

        A custom message to identify the timer.

    EXTRA_SKIP_UI

        A boolean specifying whether the responding app should skip its UI when setting the timer. If true, the app should bypass any confirmation UI and simply start the specified timer.

Example intent:

public void startTimer(String message, int seconds) {
Intent intent = new Intent(AlarmClock.ACTION_SET_TIMER)
.putExtra(AlarmClock.EXTRA_MESSAGE, message)
.putExtra(AlarmClock.EXTRA_LENGTH, seconds)
.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Note:

In order to invoke the ACTION_SET_TIMER intent, your app must have the SET_ALARM permission:
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

Example intent filter:
<activity ...>
<intent-filter>
<action android:name="android.intent.action.SET_TIMER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

2.Show all alarms

To show the list of alarms, use the ACTION_SHOW_ALARMS action.

Although not many apps will invoke this intent (it's primarily used by system apps), any app that behaves as an alarm clock should implement this intent filter and respond by showing the list of current alarms.

Note: This intent was added in Android 4.4 (API level 19).

Action

    ACTION_SHOW_ALARMS
Data URI

    None
MIME Type

    None

Example intent filter:
<activity ...>
<intent-filter>
<action android:name="android.intent.action.SHOW_ALARMS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

3.Calendar

Add a calendar event

To add a new event to the user's calendar, use the ACTION_INSERT action and specify the data URI with Events.CONTENT_URI. You can then specify various event details using extras defined below.

Action

    ACTION_INSERT
Data URI

    Events.CONTENT_URI
MIME Type

    "vnd.android.cursor.dir/event"
Extras

    EXTRA_EVENT_ALL_DAY

        A boolean specifying whether this is an all-day event.

    EXTRA_EVENT_BEGIN_TIME

        The start time of the event (milliseconds since epoch).

    EXTRA_EVENT_END_TIME

        The end time of the event (milliseconds since epoch).

    TITLE

        The event title.

    DESCRIPTION

        The event description.

    EVENT_LOCATION

        The event location.

    EXTRA_EMAIL

    A comma-separated list of email addresses that specify the invitees.

Many more event details can be specified using the constants defined in the CalendarContract.EventsColumns class.

Example intent:
public void addEvent(String title, String location, Calendar begin, Calendar end) {
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Events.CONTENT_URI)
.putExtra(Events.TITLE, title)
.putExtra(Events.EVENT_LOCATION, location)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, begin)
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Example intent filter:
<activity ...>
<intent-filter>
<action android:name="android.intent.action.INSERT" />
<data android:mimeType="vnd.android.cursor.dir/event" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息