Fisrt of all be sure your manifest have the internet permission
"uses-permission android:name="android.permission.INTERNET"
then after SDK8 you must use a thread like this
public class MainActivity extends Activity implements OnClickListener
{
public static final String DEST_IP = "192.168.1.7";
public static final int DEST_UDP_PORT = 1234;
public static final byte[] buf = {'H','e','l','l','o',' ','U','D','P'};
public Button Send_UDP_Button;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Send_UDP_Button = (Button)findViewById(R.id.button1);
Send_UDP_Button.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
new Thread(new Client()).start();
}
public class Client implements Runnable
{
@Override
public void run()
{
try
{
InetAddress serverAddr = InetAddress.getByName(DEST_IP);
DatagramSocket socket = new DatagramSocket();
DatagramPacket packet = new DatagramPacket(buf, buf.length, serverAddr, DEST_UDP_PORT);
socket.send(packet);
socket.close();
}
catch (Exception e)
{
Log.w("Too Bad",e);
}
}
}
}
I hope this will help ! Sorry can't vote up your question I don't have enough reputation ! :-(