1. 程式人生 > >註冊動態監聽

註冊動態監聽

//        ---------------------------------------------------------------------------
//        註冊監聽
        MyBroadcastReceiver myBroadcastReceiver = new MyBroadcastReceiver();

        IntentFilter filter = new IntentFilter();

        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);

//        上下文
        getActivity().registerReceiver(myBroadcastReceiver,filter);
//---------------------------------------------------------------------------