美文网首页
android开机接收到多次CONNECTIVITY_ACTIO

android开机接收到多次CONNECTIVITY_ACTIO

作者: 大胡子的机器人 | 来源:发表于2019-10-22 10:39 被阅读0次

由于业务场景需要用到根据网络连接自动化执行操作,但android开机后连接广播又感觉不靠谱,因此就这个广播研究了一下参数,大致流程如下:


有sim卡和wifi联网广播顺序

大致代码如下:

    switch (intent.getAction()) {
        case ConnectivityManager.CONNECTIVITY_ACTION:  //开机会有一次广播
            NetworkInfo networkInfo = intent.getParcelableExtra("networkInfo");
            if (NetUtils.isNetConnected(context) && networkInfo.isConnected()) {
                Bundle extras = intent.getExtras();
                Set<String> strings = extras.keySet();
                for (String keyStr:strings) {
                    if(extras.get(keyStr) instanceof Integer){
                        Log.v(TAG,"intent extras(int) :"+ keyStr + ":" + extras.get(keyStr));
                    }else if(extras.get(keyStr) instanceof String){
                        Log.v(TAG,"intent extras(String) :" + keyStr + ":" + extras.get(keyStr));
                    }else{
                        Log.v(TAG,"intent extras() :" + keyStr + ":" + extras.get(keyStr));
                    }
                }
                Log.i(TAG, "网络连接成功 action=" + intent.getAction() + ";mCurrDeviceStatus=" + mCurrDeviceStatus);
                }
            } else {
                Log.e(TAG, "网络断开");
            }
            break;
    }

看下广播日志:

2019-10-21 18:31:16.119 1592-1592/xxx.xxx I/SplashFragmentNew: onCallStateChanged state=0;incomingNumber=;simCard=SIM_CARD_1
2019-10-21 18:31:16.119 1592-1592/xxx.xxx I/SplashFragmentNew: onCallStateChanged state=0;incomingNumber=;simCard=SIM_CARD_1
2019-10-21 18:31:16.618 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras() :networkInfo:[type: MOBILE[EDGE], state: CONNECTED/CONNECTED, reason: (unspecified), extra: cmnet, failover: false, available: true, roaming: false]
2019-10-21 18:31:16.618 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras(int) :networkType:0
2019-10-21 18:31:16.619 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras(int) :inetCondition:0
2019-10-21 18:31:16.619 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras(String) :extraInfo:cmnet
2019-10-21 18:31:16.619 1592-1592/xxx.xxx I/SplashFragmentNew: 网络连接成功 action=android.net.conn.CONNECTIVITY_CHANGE;mCurrDeviceStatus=INIT

2019-10-21 18:31:17.910 1592-1592/xxx.xxx I/SplashFragmentNew: onCallStateChanged state=0;incomingNumber=;simCard=SIM_CARD_1
2019-10-21 18:31:17.911 1592-1592/xxx.xxx I/SplashFragmentNew: onCallStateChanged state=0;incomingNumber=;simCard=SIM_CARD_1
2019-10-21 18:31:20.060 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras() :networkInfo:[type: MOBILE[EDGE], state: DISCONNECTED/DISCONNECTED, reason: connected, extra: cmnet, failover: false, available: true, roaming: false]
2019-10-21 18:31:20.060 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras(int) :networkType:0
2019-10-21 18:31:20.064 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras(String) :reason:connected
2019-10-21 18:31:20.064 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras(int) :inetCondition:0
2019-10-21 18:31:20.064 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras(String) :extraInfo:cmnet
2019-10-21 18:31:20.064 1592-1592/xxx.xxx I/SplashFragmentNew: 网络连接成功 action=android.net.conn.CONNECTIVITY_CHANGE;mCurrDeviceStatus=INIT

2019-10-21 18:31:20.080 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras() :networkInfo:[type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), failover: false, available: true, roaming: false]
2019-10-21 18:31:20.081 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras(int) :networkType:1
2019-10-21 18:31:20.081 1592-1592/xxx.xxx V/SplashFragmentNew: intent extras(int) :inetCondition:0
2019-10-21 18:31:20.081 1592-1592/xxx.xxx I/SplashFragmentNew: 网络连接成功 action=android.net.conn.CONNECTIVITY_CHANGE;mCurrDeviceStatus=INIT

相关文章

  • android开机接收到多次CONNECTIVITY_ACTIO

    由于业务场景需要用到根据网络连接自动化执行操作,但android开机后连接广播又感觉不靠谱,因此就这个广播研究了一...

  • Android车联网面试题

    Class类的加载 Android 的开机过程 handle 的基本原理, 当接收到了一个延时消息后又接收到了新的...

  • Android 开机自启动 App

    Android 设备开机自启动的可以用广播实现,因为 Android 设备开机时会发送一条开机广播 "androi...

  • Android App 开机自启动

    Android 设备开机自启动的可以用广播实现,因为 Android 设备开机时会发送一条开机广播 "androi...

  • Android 跳过Gapps开机引导

    Android 跳过Gapps开机引导 Android手机在刷了Gapps之后,在开机进入系统时会进入Gapps的...

  • Android系统开机流程

    1.系统开机流程图 2 Android开机各阶段 2.1 BootLoader阶段 Android 设备上电后,首...

  • Android系统启动-Init进程

    Android开机启动流程 如图1所示,是Android开机启动大致流程,其中流程大致为加载BootLoader ...

  • [Boot]硬件上电到Bootloader

    概述 ​ 本系列简要介绍Android开机流程,用于整体了解Android的启动流程。进一步为开机优化...

  • Android APK权限

    开机自动允许android.permission.RECEIVE_BOOT_COMPLETED,允许程序开机自动运...

  • 2019-03-06

    Android 定时开机方案 此方案用于实现Android主板的定时开机与Watchdog功能,应用于一些特殊产品...

网友评论

      本文标题:android开机接收到多次CONNECTIVITY_ACTIO

      本文链接:https://www.haomeiwen.com/subject/xzcxvctx.html