Java 无法解析SetLateStevenInfo方法
我最近开发了一个应用程序,但是Android studio不再支持Java 无法解析SetLateStevenInfo方法,java,android,android-notifications,Java,Android,Android Notifications,我最近开发了一个应用程序,但是Android studio不再支持setLatestEventInfo方法,因此,我尝试将此方法更改为Notification.Builder方法。但是,我正在努力,因此我希望有人能支持我将此方法更改为Notification.Builder方法 String ns = Context.NOTIFICATION_SERVICE; mNotificationManager = (NotificationManager) getSystemServic
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);
我试过下面的方法,但是,它说它不能解决这个问题
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);
我试过下面的方法,但是,它说它不能解决这个问题
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);
这是因为您未能将原始代码中的某些行复制到修改后的代码中:
Intent notificationIntent = new Intent(this,StartActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
在开始配置Notification.Builder
之前,请在修订后的代码中包含这些内容
我试过下面的方法,但是,它说它不能解决这个问题
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);
这是因为您未能将原始代码中的某些行复制到修改后的代码中:
Intent notificationIntent = new Intent(this,StartActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
在开始配置
Notification.Builder
“我正在努力”之前,请在修改后的代码中包含这些内容--请编辑您的问题,并显示您尝试过的内容以及遇到的具体问题。在这个话题上存在着很多问题,比如。如果你不希望别人将你的问题标记为重复问题,你需要详细解释你的问题与现有问题的不同之处。更新的问题我已经修改了代码,但仍然收到同样的信息,即无法解决symbol contentintent。“我正在努力”--请编辑您的问题,并显示您尝试过的内容以及遇到的具体问题。在这个话题上存在着很多问题,比如。如果您不希望别人将您的问题标记为重复问题,您需要详细解释您的问题与现有问题的不同之处。更新的问题我已修改了代码,但仍然收到相同的消息,该消息表示无法解决symbol contentintent。但是,我尝试了以下方法,它说它无法解析符号contentintent。@ElderlyWatch:正如我所写的,在开始配置Notification.Builder
之前,请在修改后的代码中包含这些内容。在开始配置Notification.Builder
之后,您就拥有了它们。例如,您可以将它们作为代码段的第一行。但是,我已经这样做了,现在我收到一条错误消息,该消息是由以下原因引起的:java.lang.NullPointerException:尝试调用虚拟方法'void android.app.NotificationManager.notify(int,android.app.Notification)'在空对象上reference@ElderlyWatch:您摆脱了mNotificationManager=(NotificationManager)getSystemService(ns)代码>行。在使用mNotificationManager
之前,您需要为它指定一个值。我尝试了以下方法,但它表明它无法解析符号contentintent。@ElderlyWatch:正如我所写的,在开始配置通知.Builder
之前,请在修改后的代码中包含这些值。在开始配置Notification.Builder
之后,您就拥有了它们。例如,您可以将它们作为代码段的第一行。但是,我已经这样做了,现在我收到一条错误消息,该消息是由以下原因引起的:java.lang.NullPointerException:尝试调用虚拟方法'void android.app.NotificationManager.notify(int,android.app.Notification)'在空对象上reference@ElderlyWatch:您摆脱了mNotificationManager=(NotificationManager)getSystemService(ns)代码>行。在使用之前,您需要为mNotificationManager
分配一个值。