Reputation: 984
I want to listen to internet access on Android App,if not available internet hide AdMob Area. By the way my application context are will be wider. If there is internet access, i want to show AdMob and Area. How can I do it? thanks
Upvotes: 0
Views: 671
Reputation: 20196
Register the following as a BroadcastReceiver to find out when the internet connection changes. When you have connection you can display the AdView.
private BroadcastReceiver wifiConnectionListener = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
final boolean isOnline = (networkInfo != null && networkInfo.isConnected());
Log.d(TAG, "#onReceive wifiNetworkInfo=" + networkInfo);
Log.d(TAG, "#onReceive online=" + isOnline + " isConnected=" + getMessageSender().isConnected());
if (isOnline) {
Log.d(TAG, "#onReceive showing AdView");
// TODO Show your AdView
}
}
};
And then register the BroadcastListsner
getActivity().registerReceiver(wifiConnectionListener,
new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
Upvotes: 0
Reputation: 12919
That already is the default behaviour of AdMob. You don't have to do anything.
Upvotes: 3