Note that there are some explanatory texts on larger screens.

plurals
  1. POListen to when Android/GoogleTV is disconnected from a WAN
    primarykey
    data
    text
    <p>I want to listen for when the GoogleTV device is disconnected and then display a pop up warning.</p> <p>I thought I had achieved this by the below code, but then discovered that I am only warned about the disconnection when the device's ethernet cable is disconnected: i.e. LAN. I am not alerted when the router's input ethernet cable is disconnected: i.e. WAN.</p> <p>I have discovered that when disconnecting the LAN cable, the GTV device will lose its IP address, but when disconnecting the WAN cable, the GTV device WILL still have an IP address - that is why it I am not alerted that the app lost a connection.</p> <p>So how do I check when a GoogleTV device is no longer connected to a WAN? What do I need to add to the below code to do that?</p> <pre><code>startListeningToNetwork(); private void startListeningToNetwork() { if(_networkStateReceiver == null){ //Listen for when the network changes. If app loses internet before webView has loaded, then display error message. _networkStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if(!isConnected()){ showNetworkErrorDialog(); } else { closeNetworkError(); } } }; IntentFilter networkFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); getActivity().registerReceiver(_networkStateReceiver, networkFilter); } } private boolean isConnected() { ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); Toast.makeText(getActivity(), "isConnected? " + (cm.getActiveNetworkInfo() != null &amp;&amp; cm.getActiveNetworkInfo().isConnected()) , Toast.LENGTH_SHORT).show(); return (cm.getActiveNetworkInfo() != null &amp;&amp; cm.getActiveNetworkInfo().isConnected()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload