ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

android tutorial pubsub does't subscribe from a pc node

asked 2013-08-11 09:33:28 -0500

mrpiccolo gravatar image

updated 2014-01-28 17:17:37 -0500

ngrennan gravatar image

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
* /talker (http://nicolo-laptop:38914/)
* /android_gingerbread/ros_text_view (

This is the code of


import android.os.Bundle;
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(;
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


import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
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<t> 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<t> subscriber = connectedNode.newSubscriber(topicName, messageType);
subscriber.addMessageListener(new MessageListener<t>() {
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) { } }

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-10-17 01:29:00 -0500

grzebyk gravatar image

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.

edit flag offensive delete link more

answered 2013-09-09 01:12:11 -0500

C.J. gravatar image

I have the same problem ,and I still haven't solved ...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-08-11 09:33:28 -0500

Seen: 1,646 times

Last updated: Oct 17 '13