Subversion Repositories SmartDukaan

Rev

Rev 21179 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
19653 manas 1
package com.saholic.profittill.Services;
2
 
3
import android.app.IntentService;
4
import android.content.Intent;
5
import android.content.SharedPreferences;
6
import android.net.ConnectivityManager;
7
import android.util.Log;
8
 
9
import com.saholic.profittill.Network.NotificationPoll;
10
import com.saholic.profittill.Utils.UtilityFunctions;
11
 
12
import java.text.DateFormat;
13
 
14
public class PollingService extends IntentService {
15
    SharedPreferences apiData, userData;
16
    SharedPreferences.Editor apiEditor,userEditor;
17
    public PollingService() {
18
        super("PollingService");
19
    }
20
 
21
    @Override
22
    protected void onHandleIntent(Intent intent) {
23
        userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
24
        apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
25
        userEditor = userData.edit();
26
        apiEditor = apiData.edit();
27
        userEditor.putString("alarm_set","true").commit();
28
        if(isInternetOn()) {
29
            String url = apiData.getString("pollnotification.url", "http://45.33.50.227:3001/pollNotifications") + "?user_id=" + userData.getString("id", "") + "&android_id=" + UtilityFunctions.androidId(getApplicationContext());
30
            new NotificationPoll().fetchNotfications(getApplicationContext(), null, url);
31
        }
32
    }
33
 
34
    public final boolean isInternetOn() {
35
        ConnectivityManager connec = (ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
36
        if ( connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
37
                connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
38
                connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
39
                connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
40
            return true;
41
 
42
        } else if (
43
                connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
44
                        connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED  ) {
45
            return false;
46
        }
47
        return false;
48
    }
49
}