解决方法
有关更多信息,请参阅此
Link.
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
编辑
// 1.获取NotificationManager的引用
String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
// 2.实例化通知
int icon = R.drawable.notification_icon; CharSequence tickerText = "Hello"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon,tickerText,when);
// 3.定义Notification的扩展消息和Intent
Context context = getApplicationContext(); CharSequence contentTitle = "My notification"; CharSequence contentText = "Hello World!"; Intent notificationIntent = new Intent(this,MyClass.class); PendingIntent contentIntent = PendingIntent.getActivity(this,notificationIntent,0); notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent);
// 4.将通知传递给NotificationManager
private static final int HELLO_ID = 1; mNotificationManager.notify(HELLO_ID,notification);
// ———————-
//添加声音
// ———————-
// 一个.默认声音
notification.defaults |= Notification.DEFAULT_SOUND;
// b.来自SD卡的自定义声音
notification.sound = Uri.parse("file:///sdcard/notification/SOUND.mp3");
// ———————-
//添加振动
// ———————-
// 一个.默认振动
notification.defaults |= Notification.DEFAULT_VIBRATE;
// b.定制振动
long[] vibrate = {0,100,200,300}; notification.vibrate = vibrate;
// ————————
//添加闪烁灯
// ————————
// 一个.默认灯光
notification.defaults |= Notification.DEFAULT_LIGHTS;
// b.定制灯
notification.ledARGB = 0xff00ff00; notification.ledOnMS = 300; notification.ledOffMS = 1000; notification.flags |= Notification.FLAG_SHOW_LIGHTS;