Rev 21179 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.saholic.profittill.Services;import android.app.IntentService;import android.content.Intent;import android.content.SharedPreferences;import android.net.ConnectivityManager;import android.util.Log;import com.saholic.profittill.Network.NotificationPoll;import com.saholic.profittill.Utils.UtilityFunctions;import java.text.DateFormat;public class PollingService extends IntentService {SharedPreferences apiData, userData;SharedPreferences.Editor apiEditor,userEditor;public PollingService() {super("PollingService");}@Overrideprotected void onHandleIntent(Intent intent) {userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);userEditor = userData.edit();apiEditor = apiData.edit();userEditor.putString("alarm_set","true").commit();if(isInternetOn()) {String url = apiData.getString("pollnotification.url", "http://45.33.50.227:3001/pollNotifications") + "?user_id=" + userData.getString("id", "") + "&android_id=" + UtilityFunctions.androidId(getApplicationContext());new NotificationPoll().fetchNotfications(getApplicationContext(), null, url);}}public final boolean isInternetOn() {ConnectivityManager connec = (ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);if ( connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {return true;} else if (connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED ) {return false;}return false;}}