In the settings application I'm trying to receive message about changing network status. It looks like this:
<receiver android:name="com.android.settings.NetworkStateReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
public class NetworkStateReceiver extends BroadcastReceiver
{
public static final String TAG = "NetworkStateReceiver";
public static final String NETWORK_CHANGED_ACTION = "com.android.settings.NetworkStateReceiver.NETWORK_CHANGED";
@Override
public void onReceive( Context context, Intent intent )
{
Log.d(TAG, "Network state changed");
Intent i = new Intent();
i.setAction(NETWORK_CHANGED_ACTION);
context.sendBroadcast(i);
}
}
From this receiver I'm trying to send message to DeviceInfoFragment, there is receiver, which should catch this broadcast:
private BroadcastReceiver mNetwrokStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("NetworkStateReceiver_DEVICE_INFO", "network state changed");
if (isNetworkConnected()) {
Log.d("NetworkStateReceiver_DEVICE_INFO", "network connected");
mHelpPreference.setEnabled(true);
} else {
mHelpPreference.setEnabled(false);
Log.d("NetworkStateReceiver_DEVICE_INFO", "network disconnected");
}
}
};
I register it in onResume and unregister in onPause.
But I got error in NetworkStateReceiver in this line:
context.sendBroadcast(i);
Calling a method in the system process without a qualified user
Is there is any way to fix it?