Слушаю, изменил интернет-соединение с приемником вещанияНа переднем плане все отлично.Но он не работает, когда приложение убито.
Манифест:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Мой широковещательный приемник (NetworkReceiver):
application.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent{
}, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
NetworkConstraint:
public class NetworkConstraint implements Constraint {
@Override
public boolean isConnected() {
ConnectivityManager connectivityManager = (ConnectivityManager) application.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
@Override
public void applyToJobInfo(@NonNull JobInfo.Builder jobInfoBuilder) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
jobInfoBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
}
}
}
CellConstraint:
public class CellServiceConstraint implements Constraint {
@Override
public boolean isConnected() {
return new TelephonyServiceState().isConnected(application);
}
@Override
public void applyToJobInfo(@NonNull JobInfo.Builder jobInfoBuilder) {
}
}