gpt4 book ai didi

java - 无法解析 setLatestEventInfo 方法

转载 作者:太空宇宙 更新时间:2023-11-04 11:19:50 25 4
gpt4 key购买 nike

我最近开发了一个应用程序,但是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);

我已经尝试了以下方法,但是,它说它无法解析符号内容 Intent 。

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);

最佳答案

I have tried the below, however, it says that it cannot resolve symbol contentintent.

这是因为您未能将原始代码中的某些行复制到修改后的代码中:

    Intent notificationIntent = new Intent(this,StartActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);

在开始配置 Notification.Builder 之前,将这些内容添加到修订后的代码中。

关于java - 无法解析 setLatestEventInfo 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45042492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com