Ach*_*yan 2 android android-notifications android-vibration
我试图设置振动和声音通知.由于某种原因它不适合我:(这是我正在尝试的代码
NotificationManager notificationManager = getNotificationManager();
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
builder.setSound(alarmSound);
builder.setVibrate(new long[] { 1000, 1000, 1000 });
Notification notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(title).setWhen(0)
.setAutoCancel(true).setContentTitle(title).setPriority(Notification.PRIORITY_HIGH)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msgToDisply))
.setContentText(msgToDisply).build();
notificationManager.notify(NOTIFICATION, notification);
stopSelf();
Run Code Online (Sandbox Code Playgroud)
和
public NotificationManager getNotificationManager() {
return (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
Run Code Online (Sandbox Code Playgroud)
我的证词中有我的许可
<uses-permission android:name="android.permission.VIBRATE" />
Run Code Online (Sandbox Code Playgroud)
有什么想法发生了什么?
加上这个
notification.defaults|= Notification.DEFAULT_SOUND;
notification.defaults|= Notification.DEFAULT_LIGHTS;
notification.defaults|= Notification.DEFAULT_VIBRATE;
Run Code Online (Sandbox Code Playgroud)
小智 3
这是因为您没有声明 Vibrator 类在通知时振动。在通知生成器中放置此代码并根据您的选择设置振动持续时间。
Vibrator v = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
v.vibrate(500);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5231 次 |
| 最近记录: |