Skip to content Skip to sidebar Skip to footer

Android - Listen To Devices Over Socket And Create Their List

I am sending a broadcast message to the devices in network from my android phone and waiting for them to reply. There are n number of devices in the network. Now I need to create

Solution 1:

Finally for this, I landed using AsyncTask and the code follows here:

publicclassTestActivityextendsActivity{
protectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);
    newDeviceSearcher().execute();
}

privateclassDeviceSearcherextendsAsyncTask<Void, DeviceInformation ,Void>
{
    @OverrideprotectedvoidonPreExecute()
    {
        ....
        ....
        SomeChanges that I need to do before calling NetworkThreads
        ....
        ....
    }
    @OverrideprotectedVoiddoInBackground(Void... arg0)
    {
        newThread()
        {
            publicvoidrun()
            {
            ....
            ....//Network Thread
            ....

            publishProgress(device);//call to onProgressUpdate() method
            }
        }.start();
    returnnull;
    }
    @OverrideprotectedvoidonProgressUpdate(DeviceInformation... d)
    {
        super.onProgressUpdate(d[0]);
        /***
           * Changes in User Interface
           **/
    }
}

This will make changes to the User Interface.

Post a Comment for "Android - Listen To Devices Over Socket And Create Their List"