RosActivity crashes when switching from SpeechRecognition Activity to RosActivity [closed]
Hi all,
I tried to wrote an Android app to use SpeechRecognition Activity to get a recognized string, and use rosjava/Android_core to publish the recognized string to a topic.
But the problem is, each time when it recognized speech and switch back from SpeechRecognition activity to RosActivity, the RosActivity crash. Can anyone help to check it? Thank you.
The code is here:
https://github.com/wennycooper/Andbot...
mButton1.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// do something ....
Intent intent = new Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.UK);
try {
startActivityForResult(intent, RESULT_SPEECH);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
"Speech not supported", Toast.LENGTH_SHORT).show();
}
}
});
and
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RESULT_SPEECH:
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> matches = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if (matches.size() > 0) {
Log.d(TAG, matches.get(0));
String text = matches.get(0);
myPublisher.publishMessage(text); // added by KKUEI
}
MyPublisher is here:
public class MyPublisher extends AbstractNodeMain {
private String topic_name = "MyPublisher/messages";
private Publisher<std_msgs.String> publisher;
public MyPublisher() {
topic_name = "MyPublisher/messages";
}
public MyPublisher(String topic)
{
topic_name = topic;
}
@Override
public GraphName getDefaultNodeName() {
return GraphName.of("MyPublisher/publisher");
}
@Override
public void onStart(final ConnectedNode connectedNode) {
publisher = connectedNode.newPublisher(topic_name, std_msgs.String._TYPE);
}
public void publishMessage(String s) {
std_msgs.String str = publisher.newMessage();
str.setData(s);
publisher.publish(str);
}
}
Can you post the error log message?