android developer tiny share-20160815

今天讲使用隐示intent创建一个闹钟的例子,如下:

Alarm Clock
Create an alarm


To create a new alarm, use the ACTION_SET_ALARM action and specify alarm details such as the time and message using extras defined below.

Note: Only the hour, minutes, and message extras are available in Android 2.3 (API level 9) and higher. The other extras were added in later versions of the platform.

Action
    ACTION_SET_ALARM


Data URI
    None


MIME Type
    None


Extras
    EXTRA_HOUR

        The hour for the alarm.
    EXTRA_MINUTES
        The minutes for the alarm.
    EXTRA_MESSAGE
        A custom message to identify the alarm.
    EXTRA_DAYS
        An ArrayList including each week day on which this alarm should be repeated. Each day must be declared with an integer from the Calendar class such as MONDAY.
For a one-time alarm, do not specify this extra.


    EXTRA_RINGTONE
        A content: URI specifying a ringtone to use with the alarm, or VALUE_RINGTONE_SILENT for no ringtone.
To use the default ringtone, do not specify this extra.

    EXTRA_VIBRATE
        A boolean specifying whether to vibrate for this alarm.
    EXTRA_SKIP_UI
        A boolean specifying whether the responding app should skip its UI when setting the alarm. If true, the app should bypass any confirmation UI and simply set the specified alarm.


Example intent:

public void createAlarm(String message, int hour, int minutes) {
    Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM)
            .putExtra(AlarmClock.EXTRA_MESSAGE, message)
            .putExtra(AlarmClock.EXTRA_HOUR, hour)
            .putExtra(AlarmClock.EXTRA_MINUTES, minutes);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}


Note:
In order to invoke the ACTION_SET_ALARM 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_ALARM" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值