StateChange Add Remove叫 Network Manager 在出現 interface .. StateChange, Add, Remove 時分別 call 這三個 function.
所以..
我們寫下我們自己 implement 的 class
private class InterfaceObserver extends BaseNetworkObserver { @Override public void interfaceLinkStateChanged(String iface, boolean up) { updateInterfaceState(iface, up); } @Override public void interfaceAdded(String iface) { maybeTrackInterface(iface); } @Override public void interfaceRemoved(String iface) { stopTrackingInterface(iface); } }然後在系統啟動的時候,向 Network Management Service 註冊:
// Start tracking interface change events. mInterfaceObserver = new InterfaceObserver(); try { mNMService.registerObserver(mInterfaceObserver); } catch (RemoteException e) { Log.e(TAG, "Could not register InterfaceObserver " + e); }
沒有留言:
張貼留言