Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] automatically subscribe after a successful connection

Hi Jacarri,

I assume that you think it is not easy.  The normal way with the asynchronous Java client would be to subscribe in the callback for successful connection.

I'll be looking at the Android code soon.  Up to now it's not something I've had time for.

Ian

On 12/19/2014 01:07 AM, 陈健 wrote:
In order to automatically subscribe after a successful connection. I write a broadcastreceiver  to receive  the intents  of  "MqttService.callbackToActivity.v0". I think this should be easy.

-------------------------------------------------------------
private void registerReceiverMqtt() {
broadcastReceiver = new BroadcastReceiver() {
static final String TAG = "MqttService";
static final String CALLBACK_ACTION = TAG + ".callbackAction";
static final String CONNECT_ACTION = "connect";
static final String CALLBACK_STATUS = TAG + ".callbackStatus";
@Override
public void onReceive(Context context, Intent intent) {
String action="">
Bundle data = "">
Status status= (Status) data.getSerializable(CALLBACK_STATUS);
if (CONNECT_ACTION.equals(action)) {
if(status ==Status.OK){
try {
mqttClient.subscribe(Constants.TOPIC, 1);
} catch (MqttSecurityException e) {
e.printStackTrace();
} catch (MqttException e) {
e.printStackTrace();
}
}
}
}};
IntentFilter filter = new IntentFilter();
String  fileName="MqttService.callbackToActivity.v0";
filter.addAction(fileName );
registerReceiver(broadcastReceiver, filter);
}
-------------------------------------------------------------

------------------

Jacarri Chan



_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev

-- 
Ian Craggs                          
icraggs@xxxxxxxxxx                 IBM United Kingdom
Paho Project Lead; Committer on Mosquitto


Back to the top