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?
It is just a warning.
You can see that by looking at the source code: https://android.googlesource.com/platform/frameworks/base/+/b267554/core/java/android/app/ContextImpl.java
Just search for the method "warnIfCallingFromSystemProcess()"
If you are developing market applications you cannot eliminate this warning.
If you are a handset vendor, you can add to your manifest
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
and then can send the broadcast as an actual user.
context.sendBroadcastAsUser(i, new UserHandle(UserHandle.USER_CURRENT));
The application that is launched will get elevated permissions only if it is properly configured to do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With