目前,我正在Android中运行新环境。不幸的是,之前的开发人员在加入之前,似乎他使用的是API 22.所以,这是关于遗产的。
现在我在通知中遇到了几个问题,因为setLatestEventInfo
已被删除(23岁以上)。我面临着迁移过去方法的挑战。这是我的代码:
/depreciation/
@protected void PushNotification(String title, String message) {
String ns = Context.NOTIFICATION_SERVICE;
int NOTIFICATION_ID = 1;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = message;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = this;
CharSequence contentTitle = title;
CharSequence contentText = message;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.defaults |= Notification.DEFAULT_SOUND;
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
需要建议做正确的事情,有几条意见建议添加NotificationCompat
,但我不知道该如何做或有任何替代方法?
答案 0 :(得分:0)
尝试使用NotificationCompat.Builder