if (retransmit < 3)
{
retransmit = retransmit + 1;
$.DEBUGGER.println(Lang.format("retransmit: $1$", [retransmit]));
Comm.transmit(Communications.MESSAGE_TYPE_GET_LANGUAGE, null, new CommCheckListener());
return;
}
new CommCheckListener()
to another one, still nothing is called after this transmit call.I run into the same problem wrt item 1 : The first one is SUCCESS the second one is FAILURE_UNKNOWN
Strange that not many people have the same problem. The reversed code extracted from connectiq.jar has a file named ConnectIQAdbStrategy.java and the procedure that causes the 2nd callback:
@Override protected void sendMessageProtocol(final IQDevice device, final IQApp application, final byte[] data, final IQSendMessageListener listener) { if (AdbConnection.getInstance().sendMessage(data) && listener != null) { listener.onMessageStatus(device, application, IQMessageStatus.SUCCESS); } if (listener != null) { listener.onMessageStatus(device, application, IQMessageStatus.FAILURE_UNKNOWN); } }
Next to that I get an android.os.NetworkOnMainThreadException on
DeviceActivity.java:201 ( the call to mConnectIQ.sendMessage ) of the Comm example:
2021-01-07 15:06:55.501 15403-15403/com.garmin.android.apps.connectiq.sample.comm W/System.err: android.os.NetworkOnMainThreadException
2021-01-07 15:06:55.506 15403-15403/com.garmin.android.apps.connectiq.sample.comm W/System.err: at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303)
2021-01-07 15:06:55.507 15403-15403/com.garmin.android.apps.connectiq.sample.comm W/System.err: at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
2021-01-07 15:06:55.507 15403-15403/com.garmin.android.apps.connectiq.sample.comm W/System.err: at java.net.SocketOutputStream.write(SocketOutputStream.java:145)
2021-01-07 15:06:55.507 15403-15403/com.garmin.android.apps.connectiq.sample.comm W/System.err: at com.garmin.android.connectiq.adb.AdbConnection.sendMessage(AdbConnection.java:196)
2021-01-07 15:06:55.507 15403-15403/com.garmin.android.apps.connectiq.sample.comm W/System.err: at com.garmin.android.connectiq.ConnectIQAdbStrategy.sendMessageProtocol(ConnectIQAdbStrategy.java:127)
2021-01-07 15:06:55.507 15403-15403/com.garmin.android.apps.connectiq.sample.comm W/System.err: at com.garmin.android.connectiq.ConnectIQ.sendMessage(ConnectIQ.java:941)
2021-01-07 15:06:55.507 15403-15403/com.garmin.android.apps.connectiq.sample.comm W/System.err: at com.garmin.android.connectiq.ConnectIQ.sendMessage(ConnectIQ.java:921)
2021-01-07 15:06:55.507 15403-15403/com.garmin.android.apps.connectiq.sample.comm W/System.err: at com.garmin.android.apps.connectiq.sample.comm.DeviceActivity.onListItemClick(DeviceActivity.java:201)
2021-01-07 15:06:55.507 15403-15403/com.garmin.android.apps.connectiq.sample.comm W/System.err: at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
2021-01-07 15:06:55.507 15403-15403/com.garmin.android.apps.connectiq.sample.comm W/System.err: at android.widget.AdapterView.performItemClick(AdapterView.java:339)
Android says: The exception that is thrown when an application attempts to perform a networking operation on its main thread.
Maybe that is due to changed Android design rules. The old (commented out) and modified code:
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
final Object message = MessageFactory.getMessage(this, position);
// try {
// mConnectIQ.sendMessage(mDevice, mMyApp, message, new IQSendMessageListener() {
// @Override
// public void onMessageStatus(IQDevice device, IQApp app, IQMessageStatus status) {
// Toast.makeText(DeviceActivity.this, status.name(), Toast.LENGTH_SHORT).show();
// }
// });
// } catch (InvalidStateException e) {
// Toast.makeText(this, "ConnectIQ is not in a valid state", Toast.LENGTH_SHORT).show();
// } catch (ServiceUnavailableException e) {
// Toast.makeText(this, "ConnectIQ service is unavailable. Is Garmin Connect Mobile installed and running?", Toast.LENGTH_LONG).show();
// } catch (Exception e){
// e.printStackTrace();
// }
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
try {
mConnectIQ.sendMessage(mDevice, mMyApp, message, new IQSendMessageListener() {
@Override
public void onMessageStatus(IQDevice device, IQApp app, IQMessageStatus status) {
Toast.makeText(getBaseContext(), status.toString(), Toast.LENGTH_SHORT).show();
}
});
} catch (InvalidStateException e) {
Toast.makeText(getBaseContext(), "ConnectIQ is not in a valid state", Toast.LENGTH_SHORT).show();
} catch (ServiceUnavailableException e) {
Toast.makeText(getBaseContext(), "ConnectIQ service is unavailable. Is Garmin Connect Mobile installed and running?", Toast.LENGTH_LONG).show();
} catch (Exception e){
e.printStackTrace();
}
Looper.loop();
}
});
thread.start();
}
In addition you also need to change build.gradle and add gradle.properties to get it compiled.
It would be nice when you try an example (Comm) that you don't have to start solving bugs or compiler issues but thats probably... life.