Subversion Repositories SmartDukaan

Rev

Rev 19653 | Go to most recent revision | Details | Compare with Previous | 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() {
21179 rajender 18
 
19653 manas 19
        super("PollingService");
20
    }
21
 
22
    @Override
23
    protected void onHandleIntent(Intent intent) {
24
        userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
25
        apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
26
        userEditor = userData.edit();
27
        apiEditor = apiData.edit();
28
        userEditor.putString("alarm_set","true").commit();
29
        if(isInternetOn()) {
30
            String url = apiData.getString("pollnotification.url", "http://45.33.50.227:3001/pollNotifications") + "?user_id=" + userData.getString("id", "") + "&android_id=" + UtilityFunctions.androidId(getApplicationContext());
31
            new NotificationPoll().fetchNotfications(getApplicationContext(), null, url);
32
        }
33
    }
34
 
35
    public final boolean isInternetOn() {
36
        ConnectivityManager connec = (ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
37
        if ( connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
38
                connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
39
                connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
40
                connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
41
            return true;
42
 
43
        } else if (
44
                connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
45
                        connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED  ) {
46
            return false;
47
        }
48
        return false;
49
    }
50
}