最近在慢慢把Eclipse里面的项目往Android Studio里面前移,在
E
clipse没有用到过Notification.setLatestEventInfo,但到了Android Studio后,会报红字。
把格式改下即可:
//定义NotificationManager
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
Notification.Builder notification = new Notification.Builder(this);
notification.setContentInfo(tickerText);//补充内容
notification.setContentText(tickerText);//主内容区
notification.setContentTitle(contentTitle);//通知标题
notification.setSmallIcon(R.mipmap.icon);
//Context context = getApplicationContext();
notification.setTicker("新消息");
notification.setAutoCancel(true);
notification.setWhen(System.currentTimeMillis());
//Intent intent = new Intent(this,T);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setContentIntent(pendingIntent);
Notification nt = notification.build();
mNotificationManager.notify(1, nt);