Rosanswers logo

i'm writing an Android app which must publish in a topic and subscriber from an another topic. The app which publish works fine (the listener node receive the correct string), while the app which subscriber does't work if the talker node is executed by the PC, the phone does't dispay anything, (but by the phone works). What is the issue? if i write rostopic info /chatter :

Type: std_msgs/String

This is the code of MainActivity.java

package org.ros.android.android_tutorial_pubsub;

import android.os.Bundle;
import org.ros.android.MessageCallable;
import org.ros.android.RosActivity;
import org.ros.android.view.RosTextView;
import org.ros.node.NodeConfiguration;
import org.ros.node.NodeMainExecutor;
import org.ros.address.InetAddressFactory;

public class MainActivity extends RosActivity {

private RosTextView<std_msgs.String> rosTextView;

public MainActivity() {
super("Pubsub Tutorial", "Pubsub Tutorial");

public void onCreate(Bundle savedInstanceState) {
rosTextView = (RosTextView<std_msgs.String>) findViewById(R.id.text);
rosTextView.setMessageToStringCallable(new MessageCallable<String, std_msgs.String>() {
public String call(std_msgs.String message) {
return message.getData();

protected void init(NodeMainExecutor nodeMainExecutor) {
NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(InetAddressFactory.newNonLoopback().getHostAddress());
nodeMainExecutor.execute(rosTextView, nodeConfiguration);

This is the code of RosTextView.java:

package org.ros.android.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
import org.ros.android.MessageCallable;
import org.ros.message.MessageListener;
import org.ros.namespace.GraphName;
import org.ros.node.ConnectedNode;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.node.topic.Subscriber;

public class RosTextView extends TextView implements NodeMain {

private String topicName;
private String messageType;
private MessageCallable<String, T> callable;

public RosTextView(Context context) { super(context); }

public RosTextView(Context context, AttributeSet attrs) { super(context, attrs); }

public RosTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); }

public void setTopicName(String topicName) { this.topicName = topicName; }

public void setMessageType(String messageType) { this.messageType = messageType; }

public void setMessageToStringCallable(MessageCallable<String, T> callable) { this.callable = callable; }

@Override public GraphName getDefaultNodeName() { return GraphName.of("android_gingerbread/ros_text_view"); }

@Override public void onStart(ConnectedNode connectedNode) {
Subscriber subscriber = connectedNode.newSubscriber(topicName, messageType);
subscriber.addMessageListener(new MessageListener() {
public void onNewMessage(final T message) {
if (callable != null) {
post(new Runnable() {
public void run() {
} }); } else {
post(new Runnable() {
public void run() {
} }); } postInvalidate();
} });

@Override public void onShutdown(Node node) { }

@Override public void onShutdownComplete(Node node) { }

@Override public void onError(Node node, Throwable throwable) { } }

Originally posted by mrpiccolo on ROS Answers with karma: 36 on 2013-08-11

Post score: 0


1 Answer 1


Rosanswers logo

Check your ROS variables by typing env | grep ROS into terminal. ROS_IP and ROS_MASTER_URI must be set to the actual pc's ip address.

Originally posted by grzebyk with karma: 141 on 2013-10-17

This answer was ACCEPTED on the original site

Post score: 1


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.