在android中为通知设置Vibration,Lights或Sound的组合

栏目: Android · 发布时间: 7年前

内容简介:我想为用户提供选择灯光,声音或振动的选项或这三者的组合用于通知警报.在android文档中,我看到有一个DEFAULT_ALL选项,其中将使用所有三种警报方法.否则,有一个选项可以选择其中任何一个(DEFAULT_LIGHTS,DEFAULT_VIBRATE,DEFAULT_SOUND).

我想为用户提供选择灯光,声音或振动的选项或这三者的组合用于通知警报.

在android文档中,我看到有一个DEFAULT_ALL选项,其中将使用所有三种警报方法.

否则,有一个选项可以选择其中任何一个(DEFAULT_LIGHTS,DEFAULT_VIBRATE,DEFAULT_SOUND).

有没有什么方法可以组合例如SOUND和VIBRATION但没有LIGHTS和其他组合?

编辑

Notification.Builder(来自prolink007的答案)方法setDefaults(int default)表示:

The value should be one or more of the following fields combined with bitwise-or : DEFAULT_SOUND, DEFAULT_VIBRATE, DEFAULT_LIGHTS.

该如何使用?

Notification.Builder API 11NotificationCompat.Builder API 1

提供了一些设置这些类型警报的不同方法.

> setLights(…)

> setSound(…)

> setVibrate(…)

The value should be one or more of the following fields combined with bitwise-or: DEFAULT_SOUND, DEFAULT_VIBRATE, DEFAULT_LIGHTS.

未经测试,但我相信如果你想要声音,振动和灯光,你会做这样的事情:

setDefaults(DEFAULT_SOUND | DEFAULT_VIBRATE | DEFAULT_LIGHTS);

翻译自:https://stackoverflow.com/questions/12006724/set-a-combination-of-vibration-lights-or-sound-for-a-notification-in-android


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The NSHipster Fake Book (Objective-C)

The NSHipster Fake Book (Objective-C)

Mattt Thompson / NSHipster Portland, Oregon / 2014 / USD 19.00

Fake Books are an indispensable tool for jazz musicians. They contain the melody, rhythm, and chord changes for hundreds of standards, allowing a player to jump into any session cold, and "fake it" th......一起来看看 《The NSHipster Fake Book (Objective-C)》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具