- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我制作了提醒应用程序,但无法解析方法 setLatestEventInfo
方法。
public class NotifyService extends Service {
public class ServiceBinder extends Binder {
NotifyService getService() {
return NotifyService.this;
}
}
private static final int NOTIFICATION = 123;
public static final String INTENT_NOTIFY = "com.example.seng.healthyapp.INTENT_NOTIFY";
private NotificationManager mNM;
@Override
public void onCreate() {
Log.i("NotifyService", "onCreate()");
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("LocalService", "Received start id " + startId + ": " + intent);
if (intent.getBooleanExtra(INTENT_NOTIFY, false))
showNotification();
return START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
private final IBinder mBinder = new ServiceBinder();
private void showNotification() {
CharSequence title = "Alarm!!";
int icon = R.drawable.ic_dialog_alert;
CharSequence text = "Your notification time is upon us.";
long time = System.currentTimeMillis();
Notification notification = new Notification(icon, text, time);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, SecondActivity.class), 0);
notification.setLatestEventInfo(this, title, text, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION, notification);
stopSelf();
}
}
编辑
public class NotifyService extends Service {
public class ServiceBinder extends Binder {
NotifyService getService() {
return NotifyService.this;
}
}
private static final int NOTIFICATION = 123;
public static final String INTENT_NOTIFY = "com.example.seng.healthyapp.INTENT_NOTIFY";
private NotificationManager mNM;
@Override
public void onCreate() {
Log.i("NotifyService", "onCreate()");
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("LocalService", "Received start id " + startId + ": " + intent);
if(intent.getBooleanExtra(INTENT_NOTIFY, false))
showNotification();
return START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
private final IBinder mBinder = new ServiceBinder();
private void showNotification() {
CharSequence title = "Alarm!!";
int icon = R.drawable.ic_dialog_alert;
CharSequence text = "Your notification time is upon us.";
long time = System.currentTimeMillis();
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, SecondActivity.class), 0);
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(icon)
.setContentTitle(title)
.setContentText(text)
.setContentIntent(contentIntent);
Notification notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION, notification);
stopSelf();
}
}
最佳答案
“setLatestInfo”已在 API 23 中删除:https://developer.android.com/sdk/api_diff/23/changes/android.app.Notification.html
您应该改用Notification.Builder
:https://developer.android.com/reference/android/app/Notification.Builder.html
有一个例子here .
我假设您使用的是过时的 Android 教程。尝试使用https://developer.android.com中的那些。他们是最可靠的。
关于java - 无法解析方法 `setLatestEventInfo`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39819659/
我制作了提醒应用程序,但无法解析方法 setLatestEventInfo 方法。 public class NotifyService extends Service { public cl
我知道“setLatestEventInfo”已被弃用。但我必须使用它来兼容 api lv 8 设备,因为新的通知调用功能与 api 8 设备不兼容。 我在某些项目中使用了“setLatestEven
这个问题已经有答案了: Cannot Resolve Method setLatestEventInfo (4 个回答) 已关闭 7 年前。 我正在尝试为我的应用程序实现提醒功能(API 23)。 但
我正在尝试在 api 级别 10 和以下是我的代码,但我收到语法错误 setLatestEventInfo 无法解决。我猜它与 API 级别有关 public static void sendNot
我正在处理通知,我必须使用 setLatestEventInfo。但是,Android Studio 显示以下错误消息: cannot resolve method setLatestEventinf
您好,我在这一点上有库存,其中“setLatesEventInfo”有错误。我知道 setLatestEventInfo 不会在 API 23 及更高版本上运行。有人可以帮助我如何运行这段代码吗?我的
我最近开发了一个应用程序,但是Android studio不再支持setLatestEventInfo方法,因此,我尝试将此方法更改为Notification.Builder方法。但是,我很挣扎,因此
我正在更新我的应用,使其与 Android 6.0 中的新权限模型保持一致。更新了我的 build.gradle 文件后,我现在收到了停止构建的编译消息: Warning:com.google.and
我正在创建一个模拟推送通知应用程序。它从用户那里获取输入并在设备上显示本地推送通知。据我所知,setLatestEventInfo 方法在新的 API (23+) 级别中已停用。我想知道代码的可能补丁
我在 Android Studio 中工作并尝试在特定日期和时间生成通知。一切正常,但是,在我的服务类 setLatestEventInfo() 方法中无法解析。我在 eclipse 中做过同样的演示
Feel free to improve the title I'm a little uncreative in this special case. 我正在实现一个单元测试来检查通知,我知道这几乎
Notification notification = new Notification(R.drawable.stat_sample, getText
我无法修复在 Eclipse 中遇到的此错误。这是一个引进的项目。除了这个错误之外,其他一切都正常: The method setLatestEventInfo(Context, String, St
我正在尝试在我的应用程序中实现推送通知,但它在“setLatestEventInfo”上给出错误。我做错了什么? 这是我的代码GcmMessageHandler.java: public class
我无法使用 API 26 更新应用。当我尝试运行项目时出现以下错误 错误: "ServerRunningNotification.java": error: cannot find symbol me
我是一名优秀的程序员,十分优秀!