APIDEMO NOTIFICATION

阅读更多

NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

// The details of our fake message
CharSequence from = "Joe";
CharSequence message = "kthx. meet u for dinner. cul8r";

// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, IncomingMessageView.class), 0);

// The ticker text, this uses a formatted string so our message could be localized
String tickerText = getString(R.string.imcoming_message_ticker_text, message);

// construct the Notification object.
Notification notif = new Notification(R.drawable.stat_sample, tickerText,
System.currentTimeMillis());

// Set the info for the views that show in the notification panel.
notif.setLatestEventInfo(this, from, message, contentIntent);

1: // after a 100ms delay, vibrate for 250ms, pause for 100 ms and
// then vibrate for 500ms.
notif.vibrate = new long[] { 100, 250, 100, 500}; //设置震动模式

2: notification.defaults = 提示模式 eg
setDefault(Notification.DEFAULT_SOUND); //默认声音
setDefault(Notification.DEFAULT_VIBRATE);//默认震动
setDefault(Notification.DEFAULT_ALL);//声音+震动

3:/ /自己设定消息提示View
// our custom view
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.status_bar_balloon);
contentView.setTextViewText(R.id.text, text);
contentView.setImageViewResource(R.id.icon, moodId);
notif.contentView = contentView;

// Note that we use R.layout.incoming_message_panel as the ID for
// the notification. It could be any integer you want, but we use
// the convention of using a resource id for a string related to
// the notification. It will always be a unique number within your
// application.
nm.notify(R.string.imcoming_message_ticker_text, notif);

你可能感兴趣的:(APIDEMO NOTIFICATION)