Android Open Source - MyClimateAndroidWidget Fetch Data Intent Service






From Project

Back to project page MyClimateAndroidWidget.

License

The source code is released under:

Apache License

If you think the Android project MyClimateAndroidWidget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.migesok.myclimate;
// w  ww.  j av  a 2  s  . c  om
import android.app.IntentService;
import android.content.ComponentName;
import android.content.Intent;
import android.util.Log;

import static com.migesok.myclimate.MyClimateAppWidgetProvider.ACTION_FETCH_RESULT;
import static com.migesok.myclimate.MyClimateAppWidgetProvider.EXTRA_FETCH_SUCCESS;
import static com.migesok.myclimate.MyClimateAppWidgetProvider.EXTRA_OUTSIDE_TEMP;

public class FetchDataIntentService extends IntentService {
    public FetchDataIntentService() {
        super("FetchDataIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Log.d("MyClimateWidget.FetchDataIntentService", "fetching data");
        boolean success = false;
        float outsideTemperature = Float.NaN;

        try {
            outsideTemperature = new WeatherNsuClient().getCurrentTemperature();
            success = true;
        } catch (Exception e) {
            Log.d("MyClimateWidget.FetchDataIntentService", "temperature acquisition failed", e);
        }

        Intent resultIntent = new Intent();
        resultIntent.setAction(ACTION_FETCH_RESULT);
        resultIntent.setComponent(new ComponentName(this, MyClimateAppWidgetProvider.class));
        resultIntent.addCategory(Intent.CATEGORY_DEFAULT);
        resultIntent.putExtra(EXTRA_FETCH_SUCCESS, success);
        resultIntent.putExtra(EXTRA_OUTSIDE_TEMP, outsideTemperature);
        sendBroadcast(resultIntent);
        Log.d("MyClimateWidget.FetchDataIntentService", "data fetch result sent");
    }
}




Java Source Code List

com.migesok.myclimate.FetchDataIntentService.java
com.migesok.myclimate.IOUtils.java
com.migesok.myclimate.MyClimateAppWidgetProvider.java
com.migesok.myclimate.NetworkStateListener.java
com.migesok.myclimate.WeatherNsuClient.java