Search in sources :

Example 1 with Request

use of com.a5corp.weather.internet.Request in project Weather by Sparker0i.

the class NotificationService method onHandleWork.

@Override
protected void onHandleWork(@NonNull Intent intent) {
    CheckConnection checkNetwork = new CheckConnection(this);
    if (!checkNetwork.isNetworkAvailable()) {
        return;
    }
    Log.i("In", "Notification Service Alarm");
    intent = NotificationService.newIntent(this);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    prefs = new Prefs(this);
    long intervalMillis = Long.parseLong(prefs.getTime());
    if (alarmManager != null)
        if (new Prefs(this).getNotifs()) {
            alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), intervalMillis, pendingIntent);
        } else {
            alarmManager.cancel(pendingIntent);
            pendingIntent.cancel();
        }
    String city = prefs.getCity();
    String units = PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.PREF_TEMPERATURE_UNITS, Constants.METRIC);
    try {
        WeatherInfo weather;
        weather = new Request(this).getItems(city, units);
        if (new Prefs(this).getNotifs())
            weatherNotification(weather);
    } catch (IOException e) {
        Log.e(TAG, "Error get weather", e);
    }
}
Also used : WeatherInfo(com.a5corp.weather.model.WeatherInfo) Request(com.a5corp.weather.internet.Request) AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) IOException(java.io.IOException) Prefs(com.a5corp.weather.preferences.Prefs) CheckConnection(com.a5corp.weather.internet.CheckConnection)

Aggregations

AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 CheckConnection (com.a5corp.weather.internet.CheckConnection)1 Request (com.a5corp.weather.internet.Request)1 WeatherInfo (com.a5corp.weather.model.WeatherInfo)1 Prefs (com.a5corp.weather.preferences.Prefs)1 IOException (java.io.IOException)1