Hello,
I want to implement with the emulator an application that receives information when the network connection is connected or disconnected. How can I register a receiver that gets the changes in the network
connection?
I have tried this:
public class ConnectionChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
NetworkInfo mobNetInfo = ConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
}
}
IntentFilter intentFilter = new IntentFilter();
registerReceiver(new ConnectionChangeReceiver(), intentFilter);
What should be the input of the filter so that the ConnectivityManager sends information to my receiver?
And one more question.
I have done some tests with the emulator with the following code:
ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connManager.getActiveNetworkInfo();
What I get is the information that the MOBILE network type is available and its state is CONNECTED. If I disable the local area connection on my PC I get the same information.
How can make the network information change? How can I disable/enable the connection for simulations?
Thank you in advance.
Best wishes!

