分分时时彩走势图

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

    <code id='QUyEHr'><strong id='QUyEHr'></strong></code>

    <fieldset id='QUyEHr'></fieldset>
          <span id='QUyEHr'></span>

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

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

                service action 接收器

                接登录收一次性广播,开启服务永久监听

                2019-04-18
                157次浏览

                如果现在系统只发↘送一个一次性广播(比如开◤机启动),接收器只识别一最新版次,因为系统不继续发送该广播了;现在是要在这种情况下开启服务(开机启动服务),而且登陆要连续的监听变化(如:网络改变时█,该安卓版服务启动),该怎】么处理?

                ?

                第一步:在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);// 开机启动时首次开启服务后注册接收器
                }

                }

                ?

                我要点评