我想在Android应用上收听互联网访问,如果没有互联网隐藏AdMob区域。顺便说一下,我的应用程序环境会更广泛。 如果有互联网访问,我想显示AdMob和区域。 我该怎么做? 感谢
答案 0 :(得分:2)
这已经是AdMob的默认行为。你不需要做任何事情。
答案 1 :(得分:0)
将以下内容注册为BroadcastReceiver,以了解互联网连接何时发生变化。连接后,您可以显示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
}
}
};
然后注册BroadcastListsner
getActivity().registerReceiver(wifiConnectionListener,
new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));