1

I have developed both TCP and UDP applications for Google Glass. Here is the implementation for UDP:

public class MainActivity extends Activity
{
    private TextView mTextView;
    private someRunnable mRun;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity);
        mTextView = (TextView) findViewById(R.id.textView);

        Handler mHandler = new Handler()
        {

            @Override
            public void handleMessage(Message msg)
            {
                Bundle bundle = msg.getData();
                mTextView.setText(bundle.getString("message"));
                super.handleMessage(msg);
            }
        };

        try
        {
            mRun = new someRunnable(mHandler);
            (new Thread(mRun)).start();
        }
        catch (IOException e)
        {
            Log.e("Error", "Unable to start Network activity");
            Log.e("Error", e.getLocalizedMessage());
        }
    }

    @Override
    protected void onDestroy()
    {
        mRun.stopNetworkActivity();
        super.onDestroy();
    }
}

I have a server constantly sending out packets every .5 seconds containing numbers. The Glass application receives the data and displays it on a TextView. I know that UDP is not reliable, but even with TCP I would get random "pauses" that would last for about 4 seconds followed by a lot of packet resends - By pausing of course, I mean that Glass is just dropping packets forcing the server to resend. Or even worse, with UDP just "drop and move on".

After doing further analysis, the application seems to pause ONLY when the following is shown in LogCat:

01-05 16:22:43.812: W/BluetoothAdapter(951): getBluetoothService() called with no BluetoothManagerCallback
01-05 16:22:43.812: D/BluetoothSocket(951): connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[122]}
01-05 16:22:48.203: W/bt-sdp(951): SDP - Rcvd conn cnf with error: 0x4  CID 0x40
01-05 16:22:48.203: E/btif_sock_rfcomm(951): find_rfc_slot_by_id unable to find RFCOMM slot id: 1356
01-05 16:22:53.336: W/bt-sdp(951): SDP - Rcvd conn cnf with error: 0x4  CID 0x42
01-05 16:22:53.336: E/btif_sock_rfcomm(951): find_rfc_slot_by_id unable to find RFCOMM slot id: 1357
01-05 16:22:53.336: W/BluetoothMapClientService(951): connection failed
01-05 16:22:53.336: W/BluetoothMapClientService(951): java.io.IOException: read failed, socket might closed or timeout, read ret: -1
01-05 16:22:53.336: W/BluetoothMapClientService(951):   at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:521)
01-05 16:22:53.336: W/BluetoothMapClientService(951):   at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:532)
01-05 16:22:53.336: W/BluetoothMapClientService(951):   at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:323)
01-05 16:22:53.336: W/BluetoothMapClientService(951):   at com.android.bluetooth.map.BluetoothMapClientService.connect(BluetoothMapClientService.java:262)
01-05 16:22:53.336: W/BluetoothMapClientService(951):   at com.android.bluetooth.map.BluetoothMapClientService$1.connect(BluetoothMapClientService.java:94)
01-05 16:22:53.336: W/BluetoothMapClientService(951):   at android.bluetooth.IBluetoothMapClient$Stub.onTransact(IBluetoothMapClient.java:60)
01-05 16:22:53.336: W/BluetoothMapClientService(951):   at android.os.Binder.execTransact(Binder.java:404)
01-05 16:22:53.336: W/BluetoothMapClientService(951):   at dalvik.system.NativeStart.run(Native Method)

Once the IOException is thrown, everything goes back to normal and functions smoothly.

If I connect Glass to my phone via bluetooth, the message above does not display and everything runs perfectly (no pausing).

Why is the BluetoothSocket having such an impact on my application? Is there anything that I can do besides forcing the client to be connected via bluetooth before running the application?

Zack
  • 871
  • 10
  • 24

1 Answers1

1

Check out this thread on HERE

Btw, is your project open sourced?

JavaMaMocha
  • 70
  • 1
  • 11
  • 1
    Thank you for the response. I have already seen the thread and posted a response. My project is not open sourced. The contents are saved locally on my Desktop. Although, this can be done just by creating a simple socket application and generating TCP or UDP traffic through Glass. I saw that the status said "Accepted" on the issue. Wasn't sure if that meant that they have said it was an issue and hadn't fixed it yet. Any thoughts? I contacted Glass support and they just push me to the community forums. – Zack Jan 08 '15 at 19:05
  • 1
    That seems to be their typical response. I tried to get them to add some intent supports for Glass a couple months ago, but nothing has been released since then. I don't think it would be their top priority anymore since Google has stopped selling the product – JavaMaMocha Jan 28 '15 at 17:40
  • 1
    Yeah I'm not expecting to see anything changed until 6 months from now. But you'll see me back here again with glass 3.0 if they don't fix it – Zack Jan 29 '15 at 00:05