我最近开发了一款应用,但Android Studio不再支持setLatestEventInfo
方法,因此,我尝试将此方法更改为Notification.Builder
方法。但是,我很挣扎,因此我希望有人支持我将此方法更改为Notification.Builder
方法。
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Fall Detector";
long when = System.currentTimeMillis();
notification = new Notification(icon, tickerText, when);
mContext = getApplicationContext();
CharSequence contentTitle = "Fall Detector";
CharSequence contentText = "Running";
Intent notificationIntent = new Intent(this,StartActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(mContext, contentTitle, contentText,
contentIntent);
mNotificationManager.notify(1, notification);
我已尝试过以下内容,但是,它说它无法解析符号contentintent。
String ns = Context.NOTIFICATION_SERVICE;
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Fall Detector";
long when = System.currentTimeMillis();
notification = new Notification(icon, tickerText, when);
mNotificationManager = (NotificationManager) getSystemService(ns);
Notification.Builder builder = new Notification.Builder(mContext)
.setContentTitle("Fall Detector")
.setContentText("Running")
.setContentIntent(contentIntent);
builder.build();
Notification notification = builder.getNotification();
mNotificationManager.notify(1, notification);
答案 0 :(得分:0)
我已尝试过以下内容,但是,它说它无法解析符号contentintent。
这是因为您未能将原始代码中的某些行复制到修订后的代码中:
Intent notificationIntent = new Intent(this,StartActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
在开始配置Notification.Builder
之前,请在修订后的代码中添加。