我試圖讓廣播接收機聽互聯網連接,然後連接時做一些任務。廣播接收機監控互聯網連接不工作
當我在我的真實設備上禁用或啓用我的WIFI或禁用/啓用仿真器中的數據訪問時,我沒有收到任何通知。操作CONNECTIVITY_CHANGE不再受支持。
public class InternetConnectivityReceiver extends BroadcastReceiver {
Context context;
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
Log.i(TAG, "Internet Conenction State Changed");
}
}
清單
<application
android:icon="@android:drawable/arrow_down_float"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name=".InternetConnectivityReceiver">
<intent-filter>
<action android:name="android.net.conn.BACKGROUND_DATA_SETTING_CHANGED">
</action>
</intent-filter>
</receiver>
......
</application>
可能的重複:http://stackoverflow.com/questions/3307237/how-can-i-monitor-the-network-connection-status-in-android –
它不是重複的先生。 – MSaudi
你有互聯網權限嗎? – Lucifer