excelente amigo gracias, pero me sale error al llamar al boleano dentro de la activity talves hago algo mal
Código:
package sg.peru.donest;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.Menu;
public class LoginActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
if (isOnline){
String text;
int server_port = 12345;
byte[] message = new byte[1500];
DatagramPacket p = new DatagramPacket(message, message.length);
DatagramSocket s = new DatagramSocket(server_port);
s.receive(p);
text = new String(message, 0, p.getLength());
Log.d("Udp tutorial","message:" + text);
s.close();
}
}
public boolean isOnline() {
Context context = getApplicationContext();
ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectMgr != null) {
NetworkInfo[] netInfo = connectMgr.getAllNetworkInfo();
if (netInfo != null) {
for (NetworkInfo net : netInfo) {
if (net.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
else {
Log.d("NETWORK", "No network available");
}
return false;
}