您的位置:首页 > 移动开发 > Android开发

Android 通知Notification的两种实现方法

2016-04-26 23:05 495 查看
public class NotificationActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification);
}

public void notifyNew(View view){
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = new Builder(this);
builder.setContentTitle("通知标题");
builder.setContentText("帖子内容");
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
Notification notification = builder.build();
nm.notify(0, notification);
}
@SuppressWarnings("deprecation")
public void notifyOld(View view){
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "通知来了", System.currentTimeMillis());
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:123456"));
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(this, "标题", "内容", contentIntent);
nm.notify(0, notification);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: