下面是我BroadcastReceiver
代碼在那裏我得到這個錯誤:接收廣播意圖錯誤?
java.lang.RuntimeException: Error receiving broadcast Intent { act=org.mosquitto.android.powerviewer.PING flg=0x4 (has extras)
我的代碼:
public class PingSender extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
context2 = context;
try {
System.err.println("MQTT IS NULLLLLLLLLLLLL");
mqttClient.ping();
} catch (MqttException e) {
Log.e("mqtt", "ping failed - MQTT exception", e);
try {
mqttClient.disconnect();
} catch (MqttPersistenceException e1) {
Log.e("mqtt", "disconnect failed - persistence exception", e1);
}
// reconnect
if (connectToBroker()) {
String deviceID = mPrefs.getString(PREF_DEVICE_ID, null);
;
deviceID = MQTT_CLIENT_ID + "/" + deviceID;
subscribeToTopic(deviceID);
}
}
// start the next keep alive period
scheduleNextPing();
}
}
我要檢查的第一件事是您對原始版本的代碼所做的更改。錯誤也可能存在,但值得檢查。我還要指出,你應該更新你的軟件包命名,以便它與演示(我懷疑這是查看家庭電源使用情況)和你自己的域名不相同。 – ralight