【发布时间】:2017-06-05 07:13:08
【问题描述】:
我添加了以下权限并定义了广播接收器
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".LoginActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".CheckLockBroadCastReciever" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<!--<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />-->
</intent-filter>
</receiver>
</application>`
当我在 jellybeans os、KitKat os 和 lollipop os 中打开/关闭移动数据时,我定义的接收器正在调用,但接收器没有在 marshmallow 和 nougat 中调用。
【问题讨论】:
-
你得到任何 logcat 的错误是什么?
-
我没有收到任何错误,当我在棉花糖和牛轧糖中手动启用或禁用移动数据时,接收器“CheckLockBroadCastReciever”不会自动撤销
-
这里添加java代码
-
公共类 CheckLockBroadCastReciever 扩展 BroadcastReceiver { Context mCONtext; @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Called, internet response called", Toast.LENGTH_SHORT).show(); } }
-
抱歉,无法以正确的代码格式粘贴。没有调用 toast 消息。
标签: android android-6.0-marshmallow android-7.0-nougat