receive UDP data on Google Glass with GDK

前端 未结 2 984
后悔当初
后悔当初 2021-01-25 02:13

Any recommendations for receiving UDP data from an app running on Google Glass?

I need to integrate with an existing system. This system does UDP broadcasts to the loca

相关标签:
2条回答
  • 2021-01-25 02:49

    According to GDK welcome page:

    We designed the Glass platform to make the existing Android SDK just work on Glass. This lets you code in a familiar environment, but for a uniquely novel device.

    In addition, you can use all of the existing Android development tools, and your Glassware is even delivered as a standard Android package (APK).

    So, presumably you should be able to do something along the lines of (untested):

    byte[] buf = new byte[1024];
    DatagramSocket socket = new DatagramSocket(port);
    DatagramPacket packet = new DatagramPacket(buf, buf.length);
    socket.receive(packet);
    

    DatagramSocket reference

    0 讨论(0)
  • 2021-01-25 03:03

    Nerdtron, did you make your glass UDP code work?

    I'm in very similar situation and trying to make my UDP code work as a GDK glassware app.

    If you were successful, can you share how you made it work and also your codes?

    If not, what I have found so far are:

    1. Networking part should run in a separate thread (not in the main thread). So knowing only about DatagramSocket/Packet won't help much at all.

    2. If the app needs to continuously run and receive data/packets, AsyncTask won't help. So stop using it. I wasted lots of time. We need to create a separate thread for continuously receiving data. AsyncTask is for short or temporary tasks.

    3. GUI parts must not be manipulated in threads other than the main thread (the main thread is 'GUI' thread). Any code which attempt to manipulate any GUI part (even texts) will generate error. So in order to change GUI, thread(s) receiving data via network/internet need(s) to use 'handler' (callback).

    So continuously receiving data from network/internet and updating GUI in Android/Glass apps is not easy at all. It requires clearly understanding how things work in Android/Glass apps regarding network and GUI.

    I made my code receive UDP packets and update texts in my Glass screen so far. I'll try to share my code, findings, references, etc. later after I clean up my code and make sure it works somewhat correctly.

    Let me know if you have any questions.

    0 讨论(0)
提交回复
热议问题