// TODO: better use some string instead of .class? In case I change the service class
// this could be a problem (I guess)
final Intent serviceIntent = new Intent(context, NotificationIntentService.class);
- final PendingIntent alarmIntent = PendingIntent.getService(context, 0, serviceIntent,
- PendingIntent.FLAG_UPDATE_CURRENT);
- alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime()
- + chosenInterval, chosenInterval, alarmIntent);
+ final PendingIntent alarmIntent = PendingIntent.getService(
+ context,
+ 0,
+ serviceIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ alarmMgr.setInexactRepeating(
+ AlarmManager.ELAPSED_REALTIME,
+ SystemClock.elapsedRealtime() + chosenInterval,
+ chosenInterval,
+ alarmIntent);
}
}
}
import android.app.IntentService;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
-import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import de.example.exampletdd.service.IconsList;
import de.example.exampletdd.service.PermanentStorage;
import de.example.exampletdd.service.ServiceParser;
+import de.example.exampletdd.widget.WeatherInformationWidgetProvider;
public class WidgetIntentService extends IntentService {
private static final String TAG = "WidgetIntentService";
final String urlAPI = this.getResources().getString(R.string.uri_api_weather_today);
final String url = weatherService.createURIAPICurrent(urlAPI, APIVersion,
weatherLocation.getLatitude(), weatherLocation.getLongitude());
- final String jsonData = HTTPClient.retrieveDataAsString(new URL(url));
+ final String urlWithoutCache = url.concat("&time=" + System.currentTimeMillis());
+ final String jsonData = HTTPClient.retrieveDataAsString(new URL(urlWithoutCache));
final Current current = weatherService.retrieveCurrentFromJPOS(jsonData);
// TODO: what is this for? I guess I could skip it :/
final Calendar now = Calendar.getInstance();
private void updateWidget(final RemoteViews remoteView, final int appWidgetId) {
- final AppWidgetManager manager = AppWidgetManager.getInstance(this);
+ final AppWidgetManager manager = AppWidgetManager.getInstance(this.getApplicationContext());
manager.updateAppWidget(appWidgetId, remoteView);
-
- Log.i(TAG, "updateWidget updated");
}
private void updateWidgets(final RemoteViews remoteView) {
- final ComponentName widgets = new ComponentName("de.example.exampletdd.widget", AppWidgetProvider.class.getCanonicalName());
- final AppWidgetManager manager = AppWidgetManager.getInstance(this);
+ final ComponentName widgets = new ComponentName(this.getApplicationContext(), WeatherInformationWidgetProvider.class);
+ final AppWidgetManager manager = AppWidgetManager.getInstance(this.getApplicationContext());
manager.updateAppWidget(widgets, remoteView);
-
- Log.i(TAG, "updateWidgets updated");
}
}
if (currentRemote != null) {
// 1. Check conditions. They must be the same as the ones that triggered the AsyncTask.
- final DatabaseQueries query = new DatabaseQueries(CurrentFragment.this.getActivity().getApplicationContext());
+ final DatabaseQueries query = new DatabaseQueries(context.getApplicationContext());
final WeatherLocation weatherLocation = query.queryDataBase();
- final PermanentStorage store = new PermanentStorage(CurrentFragment.this.getActivity().getApplicationContext());
+ final PermanentStorage store = new PermanentStorage(context.getApplicationContext());
final Current current = store.getCurrent();
if (current == null || !CurrentFragment.this.isDataFresh(weatherLocation.getLastCurrentUIUpdate())) {
query.updateDataBase(weatherLocation);
// 4. Update Widget's UI.
- // TODO: Unable to start service intent not found U=0 WHYYYYYYYY? ANDROID SUCKSSSSSSS
- final Intent intentWidget = new Intent();
- intentWidget.setClassName("de.example.exampletdd", WidgetIntentService.class.getCanonicalName());
- intent.putExtra("appWidgetId", 0);
+ final Intent intentWidget = new Intent(context.getApplicationContext(), WidgetIntentService.class);
intentWidget.putExtra("updateByApp", true);
- CurrentFragment.this.getActivity().getApplicationContext().startService(intent);
+ context.getApplicationContext().startService(intentWidget);
}
} else {
if (forecastRemote != null) {
// 1. Check conditions. They must be the same as the ones that triggered the AsyncTask.
- final DatabaseQueries query = new DatabaseQueries(OverviewFragment.this.getActivity().getApplicationContext());
+ final DatabaseQueries query = new DatabaseQueries(context.getApplicationContext());
final WeatherLocation weatherLocation = query.queryDataBase();
- final PermanentStorage store = new PermanentStorage(OverviewFragment.this.getActivity().getApplicationContext());
+ final PermanentStorage store = new PermanentStorage(context.getApplicationContext());
final Forecast forecast = store.getForecast();
if (forecast == null || !OverviewFragment.this.isDataFresh(weatherLocation.getLastForecastUIUpdate())) {
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
// To prevent any ANR timeouts, we perform the update in a service
- final Intent intent = new Intent(context, WidgetIntentService.class);
+ final Intent intent = new Intent(context.getApplicationContext(), WidgetIntentService.class);
intent.putExtra("appWidgetId", appWidgetId);
intent.putExtra("updateByApp", false);
context.startService(intent);
// the layout from our package).
//final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget);
- final Intent intent = new Intent(context, WidgetIntentService.class);
+ final Intent intent = new Intent(context.getApplicationContext(), WidgetIntentService.class);
intent.putExtra("appWidgetId", appWidgetId);
context.startService(intent);
}