Java 通过接口回调生成通知
我在尝试使用已实现的接口构建通知时遇到了一个问题 接口实现了一个具有4个方法的处理程序,我遇到问题的方法是onNotificationReceived() 这里是错误Java 通过接口回调生成通知,java,android,notifications,Java,Android,Notifications,我在尝试使用已实现的接口构建通知时遇到了一个问题 接口实现了一个具有4个方法的处理程序,我遇到问题的方法是onNotificationReceived() 这里是错误 构造函数NotificationCompat.Builder(新的MQTTCommunicator.MQTTEventHandler(){})未定义 公共接口MQTTCommunicator{ void connect(字符串地址,int端口);//添加添加多个连接的功能 我能做些什么来解决这个问题?我试图将is转换为MQTTEv
构造函数NotificationCompat.Builder(新的MQTTCommunicator.MQTTEventHandler(){})未定义
公共接口MQTTCommunicator{
void connect(字符串地址,int端口);//添加添加多个连接的功能
我能做些什么来解决这个问题?我试图将is转换为MQTTEventHandler,但运气不好。我这样设置它,因为所有代码都在库中实现,我希望避免硬编码应用程序项目的任何类/引用
接口基类
void disconnect();
void subscribe(String topic);
void unsubscribe(String topic);
void sendMessage(String topic, String message);
void addEventHandler(MQTTEventHandler handler);
void removeEventHandler(MQTTEventHandler handler);
CommunicatorStatus getStatus();
public interface MQTTEventHandler {
void onStatusChanged(CommunicatorStatus status, String message);
void onMessageReceived(String topic, String message);
void onException(String message);
void onNotificationReceived(String message);
}
这是在活动中创建的一个类实例,该类实现了我的基本接口类。
我将该对象命名为mComm,并且可以向其注册MQTTEventHandler
private void establishRecievers() {
MQTTEventHandler mHandler = new MQTTEventHandler() {
@Override
public void onStatusChanged(CommunicatorStatus status, String message) {
// TODO Auto-generated method stub
// Do something with status
}
@Override
public void onMessageReceived(String topic, String message) {
// TODO Auto-generated method stub
// Do something with the message
adapter.add(topic + "|||" + message);
adapter.notifyDataSetChanged();
}
@Override
public void onException(String message) {
// TODO Auto-generated method stub
// Do something with exception
}
public void onNotificationReceived(String message) {
// TODO Auto-generated method stub
// Do something with exception
Log.e("NOTIFICATION", message);
//ISSUE IS HERE
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
}
};
mComm.addEventHandler(mHandler);
}
我通过使用
getApplicationContext();
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(topic).setContentText(message);