最新的日本三级电影

  • <tr id='73acWw'><strong id='73acWw'></strong><small id='73acWw'></small><button id='73acWw'></button><li id='73acWw'><noscript id='73acWw'><big id='73acWw'></big><dt id='73acWw'></dt></noscript></li></tr><ol id='73acWw'><option id='73acWw'><table id='73acWw'><blockquote id='73acWw'><tbody id='73acWw'></tbody></blockquote></table></option></ol><u id='73acWw'></u><kbd id='73acWw'><kbd id='73acWw'></kbd></kbd>

    <code id='73acWw'><strong id='73acWw'></strong></code>

    <fieldset id='73acWw'></fieldset>
          <span id='73acWw'></span>

              <ins id='73acWw'></ins>
              <acronym id='73acWw'><em id='73acWw'></em><td id='73acWw'><div id='73acWw'></div></td></acronym><address id='73acWw'><big id='73acWw'><big id='73acWw'></big><legend id='73acWw'></legend></big></address>

              <i id='73acWw'><div id='73acWw'><ins id='73acWw'></ins></div></i>
              <i id='73acWw'></i>
            1. <dl id='73acWw'></dl>
              1. <blockquote id='73acWw'><q id='73acWw'><noscript id='73acWw'></noscript><dt id='73acWw'></dt></q></blockquote><noframes id='73acWw'><i id='73acWw'></i>

                service action 接收器

                接)收一次性廣播,開啟服務永久監聽

                2019-04-18
                155次瀏覽

                如果現在系統只發送一個一次李玉潔性廣播(比如開機啟動),接收器只識別一次,因為系統不繼續發送該廣播了;現在是要在這種情況下開啟不過白素是誰服務(開機啟動服務),而且要連〓續的監聽變化(如:網絡改變時,該服務●啟動),該怎〒麽處理?

                ?

                第一步:在manifest註冊廣播接收♀器,

                ?

                ?????

                第二步:在代碼中編寫廣播接↘收器,

                public class ClientUpdateReceiver extends BroadcastReceiver
                {

                ??? @Override
                ??? public void onReceive(Context context, Intent intent)
                ??? {

                ??????????? Intent i = new Intent();
                ??????????? i.setAction("zte.com.market.service");
                ??????????? i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                ??????????? context.startService(i);
                ??? }

                }

                第三步:編寫service類,其中需要另外編寫一個曼斯現在去追擊了廣播接收器,方便▃實時接受廣播,?

                public class UpdateService extends Service
                {
                ? private ConnectivityManager connectivityManager;
                ? private NetworkInfo info;

                ? private BroadcastReceiver mReceiver = new BroadcastReceiver() {

                ????? @Override
                ????? public void onReceive(Context context, Intent intent) {
                ????????? String action = intent.getAction();
                ????????? if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                ????????????? Log.d("Jeny", "網絡∞狀態已經改變");
                ????????????? connectivityManager = (ConnectivityManager)?????
                ?????????????????????????????????????? getSystemService(Context.CONNECTIVITY_SERVICE);
                ????????????? info = connectivityManager.getActiveNetworkInfo();?
                ????????????? if(info != null && info.isAvailable()) {
                ????????????????? String name = info.getTypeName();
                ????????????????? Log.d("Jeny", "當前網絡名風影他媽稱:" + name);
                ????????????????? Intent i = new Intent();
                ????????????????? i.setAction("zte.com.market.service");
                ????????????????? i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                ????????????????? context.startService(i);// 開啟服務
                ?????????? } else {
                ????????????????? Log.d("Jeny", "沒有可用網絡");
                ????????????? }
                ????????? }
                ????? }
                ? };
                ???
                ??? @Override
                ??? public IBinder onBind(Intent arg0)
                ??? {
                ??????? // TODO Auto-generated method stub
                ??????? return null;
                ??? }

                ??? @Override
                ??? public void onDestroy()
                ??? {
                ??????? // TODO Auto-generated method stub
                ??????? super.onDestroy();
                ??????? Log.v("Jeny", "[UpdateService]...onDestroy");
                ??? }

                ??? @Override
                ??? public int onStartCommand(Intent intent, int flags, int startId)
                ??? {
                ??????? // TODO Auto-generated method stub
                ??????????????
                ??????? ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                ??????? NetworkInfo mobileInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
                ??????? NetworkInfo wifiInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
                ????????Log.v("Jeny", "mobileInfo.isConnected()------->"+mobileInfo.isConnected()+"?? wifiInfo.isConnected()---------->"+wifiInfo.isConnected());
                ??????? if(mobileInfo.isConnected() || wifiInfo.isConnected()){
                ????????????
                ???????? }
                ??????? return super.onStartCommand(intent, flags, startId);
                ??? }

                ??? @Override
                ??? public void onCreate()
                ??? {
                ??????? // TODO Auto-generated method stub
                ??????? super.onCreate();
                ??????? IntentFilter mFilter = new IntentFilter();
                ??????? mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
                ??????? registerReceiver(mReceiver, mFilter);// 開機〓啟動時首次開啟服務後註冊接收器
                }

                }

                ?

                我要點評