I looked for MqttMessage on Google and it seems like getPayload() gives you
a byte array.

So if you know that it could be a String that says "connected", you just
need to compare the strings.

String message = new String(message.getPayload());
if(message.equals("connected")) {
// Do stuff
}

You could also check equalsIgnoreCase if you don't know the capitalization.

If that "connected" is not a string but it's on some kind of object, I'm
guessing you'll need to use serialization. But I'm just using simple Java
knowledge, I don't know your project.

Marina



On Wed, Aug 2, 2017 at 4:53 PM, MOHAMMED ashfaq <[email protected]> wrote:

> hello im new to android development could someone please help me with
> below code. i want to make if statement from the mqtt payload . how can i
> make playload = connected then show it is Textview
>
> ```
> public void messageArrived(String topic, MqttMessage message) throws
> Exception {
> subText.setText(new String(message.getPayload()));
> // Vibrator.vibrate(500);
> }
> ```
>
> --
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/android-developers.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/android-developers/1ffedcf4-be81-4ed5-acbd-
> 5067172fb79b%40googlegroups.com
> <https://groups.google.com/d/msgid/android-developers/1ffedcf4-be81-4ed5-acbd-5067172fb79b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/CACaNmX2CZozqnhVs%3D1t948RfAtMEobF6feGvOWQ4BFRxFQ%2BWTQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to