salu je suis un jeune dev et j ai un petit probleme pour tester la disonibilite de la connexion internet sous l emulateur .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package ski.oussama;
 
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.os.Bundle;
import android.widget.Toast;
 
public class TestconnetActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
 
       isNetworkAvailable(this);
 
 
    // onStart1();
 
 
 
 
 
 
    }
 
 
 
    protected void onStart1() {
		super.onStart();
      	ConnectivityManager connectivityManager =(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); 
      	NetworkInfo networkInfo =connectivityManager.getActiveNetworkInfo(); 
 
      	// Le type de connexion, réseau ou Wi-Fi.
      	int networkType = networkInfo.getType();
 
      	// Vérification de l’état de la connexion.
 
      	State networkState = networkInfo.getState(); 
 
      	if (networkState.compareTo(State.CONNECTED) == 0) 
      	{
      	Toast.makeText(this, "ok", 50000).show();
      	}
      	else
      	{
      		Toast.makeText(this, "noooo", 6000).show();
 
      	}
 
    }
 
    public static boolean isNetworkAvailable(Context context) { 
    	boolean value = false; 
    	ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 
    	NetworkInfo info = manager.getActiveNetworkInfo(); 
 
    	 if (info == null | info.isAvailable()==false) 
    	{
 
    		Toast.makeText(context, "nooooooooooooooo", 3000).show();
    	}
    	else if (info != null && info.isAvailable()) 
    	{ 
    	value = true; 
    	Toast.makeText(context, "okkkk", 3000).show();
    	}
 
 
    	return value; 
    	}
 
}

j ai essayer ces deux fonction bien sur chaqu une seule mais toujours ca me donne que la connexion est disponible alors que la je suis pas connecter !!!!

merci d avance )