SHARE
TWEET

GisService (SweaterWeather)

a guest Aug 24th, 2019 68 in 337 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package arinado.sweaterweather;
  2.  
  3. import android.app.Activity;
  4. import android.app.Service;
  5. import android.content.Intent;
  6. import android.os.AsyncTask;
  7. import android.os.IBinder;
  8.  
  9. import java.io.InputStream;
  10. import java.net.URL;
  11. import java.util.Scanner;
  12.  
  13. public class GisService extends Service {
  14.     public static final String CHANNEL = "GIS_SERVICE";
  15.     public static final String INFO = "INFO";
  16.     static URL url;
  17.  
  18.     @Override
  19.     public void onCreate() {}
  20.  
  21.     @Override
  22.     public int onStartCommand(Intent intent, int flags, int startId) {
  23.         GisAsyncTask t = new GisAsyncTask();
  24.         t.execute();
  25.         return flags;
  26.     }
  27.  
  28.     @Override
  29.     public void onDestroy() {}
  30.  
  31.     @Override
  32.     public IBinder onBind(Intent intent) {
  33.         return null;
  34.     }
  35.  
  36.     private class GisAsyncTask extends AsyncTask<Void, Void, String>  {
  37.         @Override
  38.         protected void onPostExecute(String aVoid) {
  39.             Intent i = new Intent(CHANNEL);
  40.             i.putExtra(INFO, aVoid);
  41.             sendBroadcast(i);
  42.  
  43.         }
  44.  
  45.         @Override
  46.         protected String doInBackground(Void... voids) {
  47.             String result;
  48.             try {
  49.                 Scanner in = new Scanner((InputStream) url.getContent());
  50.                 result = "{\"gis\":" + in.nextLine() + "}";
  51.             } catch (Exception e) {
  52.                 result = e.toString();
  53.             }
  54.             return result;
  55.         }
  56.     }
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top