I have a service, which is working in background if internet is true - update data false - nothing happen
How can I check internet within service ? Maybe Broadcast Receiver, but I do not understand how can I realize this
public class MyService extends Service {
final String LOG_TAG = "TEST";
public static final long NOTIFY_INTERVAL = 60 * 1000; // 60 секунд
// run on another Thread to avoid crash
private Handler mHandler = new Handler();
// timer handling
private Timer mTimer = null;
boolean isConnected;
@Override
public void onCreate() {
mTimer = new Timer();
// schedule task
mTimer.scheduleAtFixedRate(new TimeDisplayTimerTask(), 0,
NOTIFY_INTERVAL);
}
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(LOG_TAG, "onStartCommand");
return super.onStartCommand(intent, flags, startId);
}
public void onDestroy() {
mTimer.cancel();
Log.d(LOG_TAG, "onDestroy");
}
void someTask() {
if (isConnected) {
Toast.makeText(getApplicationContext(), "text",
Toast.LENGTH_SHORT).show();
}
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
class TimeDisplayTimerTask extends TimerTask {
@Override
public void run() {
// run on another thread
mHandler.post(new Runnable() {
@Override
public void run() {
someTask();
}
});
}
}
if boolean is Connected true - do somethink that is I need service receive result from broadcastreceiver