When WiFi is set to ON, is there a way to block outgoing data connection and allow only incoming data connection? Can it be controlled at framework level? If yes, can you please shed some light on this? I don't want to send data out and would be interested in receiving data only through my applications.
For ex: WhatsApp to receive incoming chats and to block outgoing chats. Gmail to receive incoming emails and to block outgoing emails
Here the idea is to limit the data usage.
Any idea where in Android Framework stack, the above uses cases be differentiated as outgoing and incoming. Blocking those uses cases at application level is not preferred.
Note - I have rooted Android phone.
you can check whether it is connected to wifi or mobile data. you can change it to as you want
/**
* Method for checking internet connectivity
*/
public static boolean isConnectedToInternet(Context mContext) {
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (activeNetwork != null) {
// connected to the internet
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
// connected to wifi
return true;
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
// connected to the mobile provider's data plan
return true;
}
}
return false;
}