Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21168 rajender 1
package com.saholic.profittill;
2
 
3
import android.app.NotificationManager;
4
import android.app.PendingIntent;
5
import android.content.Context;
6
import android.content.Intent;
7
import android.content.SharedPreferences;
8
import android.graphics.Bitmap;
9
import android.graphics.BitmapFactory;
10
import android.media.RingtoneManager;
11
import android.net.Uri;
12
import android.os.AsyncTask;
13
import android.os.Bundle;
14
import android.support.v4.app.NotificationCompat;
15
import android.util.Log;
16
 
17
import com.google.android.gms.analytics.HitBuilders;
18
import com.google.android.gms.analytics.Tracker;
19
import com.google.android.gms.common.server.converter.StringToIntConverter;
20
import com.google.firebase.messaging.FirebaseMessagingService;
21
import com.google.firebase.messaging.RemoteMessage;
22
import com.mixpanel.android.mpmetrics.MixpanelAPI;
23
import com.saholic.profittill.Constants.ProfitTillConstants;
24
import com.saholic.profittill.Network.NotificationCount;
25
import com.saholic.profittill.Utils.AnalyticsUtility;
26
import com.saholic.profittill.Utils.UtilityFunctions;
27
import com.saholic.profittill.Volley.Analytics;
28
import com.saholic.profittill.Volley.AnalyticsErrorResponse;
29
import com.saholic.profittill.Volley.AnalyticsJsonResponse;
30
import com.saholic.profittill.main.GoogleAnalyticsTracker;
31
import com.saholic.profittill.main.LoginActivity;
32
import com.saholic.profittill.main.MainActivity;
33
import com.saholic.profittill.main.ReferrerActivity;
34
 
35
import org.apache.http.HttpEntity;
36
import org.apache.http.HttpResponse;
37
import org.apache.http.NameValuePair;
38
import org.apache.http.client.HttpClient;
39
import org.apache.http.client.entity.UrlEncodedFormEntity;
40
import org.apache.http.client.methods.HttpPost;
41
import org.apache.http.impl.client.DefaultHttpClient;
42
import org.apache.http.message.BasicNameValuePair;
43
import org.apache.http.util.EntityUtils;
44
import org.json.JSONArray;
45
import org.json.JSONException;
46
import org.json.JSONObject;
47
 
48
import java.io.InputStream;
49
import java.net.HttpURLConnection;
50
import java.net.URL;
51
import java.util.ArrayList;
52
import java.util.Map;
53
 
54
/**
55
 * Created by rajender on 5/4/17.
56
 */
57
public class MyFirebaseMessagingService extends FirebaseMessagingService {
58
    SharedPreferences userData;
59
    SharedPreferences apiData;
60
    MixpanelAPI mixpanel;
61
    SharedPreferences.Editor userDataEditor;
62
    SharedPreferences.Editor apiSettingsEditor;
63
    ArrayList<NameValuePair> nameValuePairsGcm;
64
    public static int NOTIFICATION_ID = 1;
65
    private NotificationManager mNotificationManager;
66
    NotificationCompat.Builder builder;
67
    SharedPreferences notificationData;
68
    SharedPreferences.Editor notificationDataEditor;
69
    private static final String TAG = "MyFirebaseMsgService";
70
    Intent intent;
71
  Bitmap bitmap;
72
 
73
    @Override
74
    public void onMessageReceived(RemoteMessage remoteMessage) {
75
        userData = this.getSharedPreferences("User_Data", Context.MODE_PRIVATE);
76
        apiData = this.getSharedPreferences("API_Data", Context.MODE_PRIVATE);
77
        userDataEditor = userData.edit();
78
        apiSettingsEditor = apiData.edit();
79
        notificationData = this.getSharedPreferences("Notification_Data", Context.MODE_PRIVATE);
80
        notificationDataEditor = notificationData.edit();
81
        mixpanel = MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
82
        Map<String, String> data = remoteMessage.getData();
83
        if (data.containsKey("image")) {
84
            String imageUri = data.get("image");
85
            bitmap = getBitmapfromUrl(imageUri);
86
 
87
        }
88
            try {
89
               if(data.get("type").equalsIgnoreCase("update")){
90
                    new CheckNotificationExpiry().execute(data);
91
                }
92
                String campaignUserId = data.get("url").split("user_id=")[1];
93
                if (userData.getString("id", "0").equalsIgnoreCase(campaignUserId)) {
94
                    new Analytics(ProfitTillConstants.ANALYTICS_URL,
95
                            AnalyticsUtility.getAnalyticsRequest(getApplicationContext(), userData.getString("id", ""), "Notification", "Check Expiry", data.get("cid") + ""),
96
                            AnalyticsJsonResponse.getAnalyticsRequestInstance(),
97
                            AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getApplicationContext());
98
                    new CheckNotificationExpiry().execute(data);
99
                }
100
 
101
 
102
            }
103
            catch (Exception e) {
104
                e.printStackTrace();
105
                Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
106
                        GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
107
                t.send(new HitBuilders.ExceptionBuilder()
108
                        .setDescription("Exception while Checking" + e.getMessage())
109
                        .build());
110
            }
111
 
112
        }
113
 
114
        class CheckNotificationExpiry extends AsyncTask<Map, Integer, String> {
115
            Map extras;
116
 
117
            @Override
118
            protected String doInBackground(Map... params) {
119
                extras = params[0];
120
                try {
121
                    HttpClient httpclient = new DefaultHttpClient();
122
                    String notificationCheckUrl = apiData.getString("notification.check.url", "http://api.profittill.com/notification_campaigns/notificationactive");
123
                    HttpPost httppost = new HttpPost(notificationCheckUrl + "?cid=" + extras.get("cid") + "&imeinumber=" + UtilityFunctions.getImeiNumber(getApplicationContext()));
124
                    httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
125
                    HttpResponse response = httpclient.execute(httppost);
126
                    HttpEntity entity = response.getEntity();
127
                    JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
128
                    int status = response.getStatusLine().getStatusCode();
129
                    return String.valueOf(jObjGmail.getString("success"));
130
                    // return jObjGmail.getString("success");
131
                } catch (Exception e) {
132
                    e.printStackTrace();
133
                    Log.e("Fail 1", e.toString());
134
                    return "true";
135
                }
136
 
137
            }
138
 
139
            @Override
140
            protected void onPostExecute(String result) {
141
                super.onPostExecute(result);
142
                if (result.isEmpty() || result.equals(null) || result.equalsIgnoreCase("true")) {
143
                    if (notificationData.getString("cid", "").equalsIgnoreCase(extras.get("cid").toString().split("_")[0])) {
144
                        Log.d("Campaign Id is same " + notificationData.getString("cid", ""), "Campaign Id is same " + extras.get("cid").toString().split("_")[0]);
145
                    } else {
146
                        notificationDataEditor.putString("cid", extras.get("cid").toString().split("_")[0]);
147
                        notificationDataEditor.commit();
148
                        sendNotification(extras.get("message") + "", extras.get("type") + "", extras.get("title") + "", extras.get("url") + "", extras.get("cid") + "", bitmap);
149
                    }
150
                } else {
151
                    new Analytics(ProfitTillConstants.ANALYTICS_URL,
152
                            AnalyticsUtility.getAnalyticsRequest(getApplicationContext(), userData.getString("id", ""), "Notification", "Notification Expired", extras.get("cid") + ""),
153
                            AnalyticsJsonResponse.getAnalyticsRequestInstance(),
154
                            AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getApplicationContext());
155
                    nameValuePairsGcm = new ArrayList<>();
156
                    nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", "")));
157
                    nameValuePairsGcm.add(new BasicNameValuePair("cid", extras.get("cid") + ""));
158
                    nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
159
                    nameValuePairsGcm.add(new BasicNameValuePair("result", "expired"));
160
                    new NotificationRecievedData().execute(nameValuePairsGcm);
161
                }
162
            }
163
        }
164
 
165
    private void sendNotification(String msg, String type, String title, String url, String cid, Bitmap image) {
166
        JSONObject propsNotificationRecieved = new JSONObject();
167
        Bundle bundle;
168
        try {
169
            mixpanel.identify(userData.getString("id", null));
170
            propsNotificationRecieved.put("Screen", "Notification Reached");
171
            mixpanel.track("Notification Recieved", propsNotificationRecieved
172
            );
173
        } catch (JSONException e) {
174
            e.printStackTrace();
175
        }
176
        if (title.isEmpty()) {
177
            title = "ProfitMandi";
178
        }
179
        Intent resultIntent;
180
        mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
181
        if (userData.getString("id", "").isEmpty()) {
182
            resultIntent = new Intent(this, LoginActivity.class);
183
            resultIntent.setAction("Login");
184
            bundle = new Bundle();
185
            bundle.putString("cid", cid);
186
            resultIntent.putExtras(bundle);
187
        } else if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
188
            resultIntent = new Intent(this, ReferrerActivity.class);
189
            resultIntent.setAction("Login");
190
            bundle = new Bundle();
191
            bundle.putString("cid", cid);
192
            resultIntent.putExtras(bundle);
193
        } else {
194
            if (type.equalsIgnoreCase("Url")) {
195
                resultIntent = new Intent(this, MainActivity.class);
196
                bundle = new Bundle();
197
                bundle.putString("cid", cid);
198
                resultIntent.putExtras(bundle);
199
                resultIntent.setAction("20");
200
 
201
                if (url.isEmpty()) {
202
                    resultIntent.setData(Uri.parse(apiData.getString("mobile.website.url", "") + "?user_id=" + userData.getString("id", "")));
203
                } else {
204
                    resultIntent.setData(Uri.parse(url));
205
                }
206
 
207
            } else if (type.equalsIgnoreCase("Update")) {
208
                final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
209
                try {
210
                    resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
211
                } catch (android.content.ActivityNotFoundException anfe) {
212
                    resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName));
213
                }
214
            } else {
215
                if (url.contains("Profile")) {
216
                    resultIntent = new Intent(this, MainActivity.class);
217
                    bundle = new Bundle();
218
                    bundle.putString("cid", cid);
219
                    resultIntent.putExtras(bundle);
220
                    resultIntent.setAction("15");
221
                } else if (url.contains("Tutorial")) {
222
                    resultIntent = new Intent(this, MainActivity.class);
223
                    bundle = new Bundle();
224
                    bundle.putString("cid", cid);
225
                    resultIntent.putExtras(bundle);
226
                    resultIntent.setAction("7");
227
                } else if (url.contains("Contact")) {
228
                    resultIntent = new Intent(this, MainActivity.class);
229
                    bundle = new Bundle();
230
                    bundle.putString("cid", cid);
231
                    resultIntent.putExtras(bundle);
232
                    resultIntent.setAction("6");
233
                } else {
234
                    resultIntent = new Intent(this, MainActivity.class);
235
                    bundle = new Bundle();
236
                    bundle.putString("cid", cid);
237
                    resultIntent.putExtras(bundle);
238
                }
239
            }
240
        }
241
        PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, resultIntent, 0);
242
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
243
        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.pmlauncher);
244
        if (image==null) {
245
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
246
                    this).setSmallIcon(R.drawable.navigation_bar)
247
                    .setContentTitle(title)
248
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
249
                    .setContentText(msg)
250
                    .setLargeIcon(bm)
251
                    .setAutoCancel(true)
252
                    .setSound(alarmSound);
253
            mBuilder.setContentIntent(contentIntent);
254
            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
255
        } else {
256
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
257
                    this).
258
                    setSmallIcon(R.drawable.pmnotification3)
259
                    .setContentTitle(title)
260
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
261
                    .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(image))
262
                    .setContentText(msg)
263
                    .setLargeIcon(bm)
264
                    .setAutoCancel(true)
265
                    .setSound(alarmSound);
266
            mBuilder.setContentIntent(contentIntent);
267
            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
268
        }
269
 
270
        Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
271
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
272
        t.send(new HitBuilders.EventBuilder()
273
                .setCategory("Notification")
274
                .setAction("Building Notification for campaign Id " + cid)
275
                .setLabel("For User Id " + userData.getString("id", "0"))
276
                .build());
277
        new Analytics(ProfitTillConstants.ANALYTICS_URL,
278
                AnalyticsUtility.getAnalyticsRequest(getApplicationContext(), userData.getString("id", ""), "Notification", "Notification Received", cid),
279
                AnalyticsJsonResponse.getAnalyticsRequestInstance(),
280
                AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getApplicationContext());
281
        ++NOTIFICATION_ID;
282
        nameValuePairsGcm = new ArrayList<>();
283
        nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", "")));
284
        nameValuePairsGcm.add(new BasicNameValuePair("cid", cid));
285
        nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
286
        nameValuePairsGcm.add(new BasicNameValuePair("result", "recieved"));
287
        String userId = userData.getString("id", "");
288
        String androidId = UtilityFunctions.androidId(GoogleAnalyticsTracker.getAppContext());
289
        if (!userId.isEmpty() && !androidId.isEmpty()) {
290
            String notificationUrl = apiData.getString("notification.count", "http://45.33.50.227:3001/getNotificationCount") + "?user_id=" + userId + "&android_id=" + androidId;
291
            new NotificationCount().getCount(GoogleAnalyticsTracker.getAppContext(), null, notificationUrl);
292
        }
293
        new NotificationRecievedData().execute(nameValuePairsGcm);
294
    }
295
 
296
    class NotificationRecievedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
297
 
298
        @Override
299
        protected void onPreExecute() {
300
            super.onPreExecute();
301
            Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
302
                    GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
303
            t.send(new HitBuilders.EventBuilder()
304
                    .setCategory("Notification")
305
                    .setAction("Received Notification")
306
                    .setLabel("For User Id " + userData.getString("id", "0"))
307
                    .build());
308
        }
309
 
310
        @Override
311
        protected String doInBackground(ArrayList<NameValuePair>... arg0) {
312
 
313
            try {
314
                HttpClient httpclient = new DefaultHttpClient();
315
                HttpPost httppost = new HttpPost(apiData.getString("notification.data.url", "http://api.profittill.com/pushnotifications/add"));
316
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
317
                httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
318
                HttpResponse response = httpclient.execute(httppost);
319
                HttpEntity entity = response.getEntity();
320
                int status = response.getStatusLine().getStatusCode();
321
                nameValuePairsGcm.clear();
322
            } catch (Exception e) {
323
            }
324
            return "success";
325
        }
326
 
327
        @Override
328
        protected void onPostExecute(String result) {
329
            super.onPostExecute(result);
330
        }
331
    }
332
 
333
    public void sendNotificationByPolling(JSONArray objects,Context c) {
334
        userData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
335
        apiData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
336
        notificationData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("Notification_Data", Context.MODE_PRIVATE);
337
        userDataEditor = userData.edit();
338
        apiSettingsEditor = apiData.edit();
339
        notificationDataEditor = notificationData.edit();
340
 
341
        Bundle bundle;
342
 
343
        try {
344
            if (objects.length() != 0) {
345
                JSONObject obj = new JSONObject();
346
                JSONArray jsArray = new JSONArray();
347
                for (int i = 0; i < objects.length(); i++) {
348
                    JSONObject j = objects.getJSONObject(i);
349
                    String msg = j.getString("message");
350
                    String type = j.getString("type");
351
                    String title = j.getString("title");
352
                    String url = j.getString("url");
353
                    String cid = j.getString("cid");
354
                    String image=null;
355
                    if(j.has("image")) {
356
                        image = j.getString("image");
357
                        bitmap=getBitmapfromUrl(image);
358
                    }
359
                    if (notificationData.getString("cid", "").equalsIgnoreCase(cid.split("_")[0])) {
360
                        Log.d("Campaign Id is same " + notificationData.getString("cid", ""), "Campaign Id is same " + cid.split("_")[0]);
361
                    } else {
362
                        notificationDataEditor.putString("cid", cid.split("_")[0]);
363
                        notificationDataEditor.commit();
364
                        if (title.isEmpty()) {
365
                            title = "ProfitMandi";
366
                        }
367
                        Intent resultIntent;
368
                        mNotificationManager = (NotificationManager) GoogleAnalyticsTracker.getAppContext().getSystemService(NOTIFICATION_SERVICE);
369
                        if (userData.getString("id", "").isEmpty()) {
370
                            resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), LoginActivity.class);
371
                            resultIntent.setAction("Login");
372
                            bundle = new Bundle();
373
                            bundle.putString("cid", cid);
374
                            resultIntent.putExtras(bundle);
375
                        } else if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
376
                            resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), ReferrerActivity.class);
377
                            resultIntent.setAction("Login");
378
                            bundle = new Bundle();
379
                            bundle.putString("cid", cid);
380
                            resultIntent.putExtras(bundle);
381
                        }
382
                        else {
383
                            if (type.equalsIgnoreCase("Url")) {
384
                                resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), MainActivity.class);
385
                                bundle = new Bundle();
386
                                bundle.putString("cid", cid);
387
                                resultIntent.putExtras(bundle);
388
                                resultIntent.setAction("20");
389
 
390
                                if (url.isEmpty()) {
391
                                    resultIntent.setData(Uri.parse(apiData.getString("mobile.website.url", "") + "?user_id=" + userData.getString("id", "")));
392
                                } else {
393
                                    resultIntent.setData(Uri.parse(url));
394
                                }
395
 
396
                            } else if (type.equalsIgnoreCase("Update")) {
397
                                final String appPackageName = GoogleAnalyticsTracker.getAppContext().getPackageName();
398
                                try {
399
                                    resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
400
                                } catch (android.content.ActivityNotFoundException anfe) {
401
                                    resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName));
402
                                }
403
                            } else {
404
                                if (url.contains("Profile")) {
405
                                    resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), MainActivity.class);
406
                                    bundle = new Bundle();
407
                                    bundle.putString("cid", cid);
408
                                    resultIntent.putExtras(bundle);
409
                                    resultIntent.setAction("15");
410
                                } else if (url.contains("Tutorial")) {
411
                                    resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), MainActivity.class);
412
                                    bundle = new Bundle();
413
                                    bundle.putString("cid", cid);
414
                                    resultIntent.putExtras(bundle);
415
                                    resultIntent.setAction("7");
416
                                } else if (url.contains("Contact")) {
417
                                    resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), MainActivity.class);
418
                                    bundle = new Bundle();
419
                                    bundle.putString("cid", cid);
420
                                    resultIntent.putExtras(bundle);
421
                                    resultIntent.setAction("6");
422
                                } else {
423
                                    resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), MainActivity.class);
424
                                    bundle = new Bundle();
425
                                    bundle.putString("cid", cid);
426
                                    resultIntent.putExtras(bundle);
427
                                }
428
                            }
429
                        }
430
                        PendingIntent contentIntent = PendingIntent.getActivity(GoogleAnalyticsTracker.getAppContext(), NOTIFICATION_ID, resultIntent, 0);
431
                        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
432
                        Bitmap bm = BitmapFactory.decodeResource(GoogleAnalyticsTracker.getAppContext().getResources(), R.drawable.pmlauncher);
433
                        if (bitmap==null) {
434
                            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
435
                                  c )
436
                                    .setSmallIcon(R.drawable.navigation_bar)
437
                                    .setContentTitle(title)
438
                                    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
439
                                    .setContentText(msg)
440
                                    .setLargeIcon(bm)
441
                                    .setAutoCancel(true)
442
                                    .setSound(alarmSound);
443
                            mBuilder.setContentIntent(contentIntent);
444
                            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
445
                        }
446
 
447
                        else {
448
                            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
449
                                    GoogleAnalyticsTracker.getAppContext())
450
                                    .setSmallIcon(R.drawable.pmnotification3)
451
                                    .setContentTitle(title)
452
                                    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
453
                                    .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap))
454
                                    .setContentText(msg)
455
                                    .setLargeIcon(bm)
456
                                    .setAutoCancel(true)
457
                                    .setSound(alarmSound);
458
                            mBuilder.setContentIntent(contentIntent);
459
                            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
460
                        }
461
                        ++NOTIFICATION_ID;
462
                        JSONObject data = new JSONObject();
463
                        data.put("cid", cid);
464
                        data.put("user_id", userData.getString("id", null));
465
                        data.put("timestamp", UtilityFunctions.notificationDate());
466
                        data.put("result", "recieved");
467
                        jsArray.put(data);
468
                    }
469
                    obj.put("pushdata", jsArray);
470
                    String userId = userData.getString("id", "");
471
                    String androidId = UtilityFunctions.androidId(GoogleAnalyticsTracker.getAppContext());
472
                    if (!userId.isEmpty() && !androidId.isEmpty()) {
473
                        String notificationUrl = apiData.getString("notification.count", "") + "?user_id=" + userId + "&android_id=" + androidId;
474
                        new NotificationCount().getCount(GoogleAnalyticsTracker.getAppContext(), null, notificationUrl);
475
                    }
476
                }
477
                new PollNotificationRecievedData().execute(obj);
478
            }
479
        }
480
        catch (Exception e) {
481
            e.printStackTrace();
482
        }
483
    }
484
 
485
    class PollNotificationRecievedData extends AsyncTask<JSONObject, Integer, String> {
486
 
487
        @Override
488
        protected void onPreExecute() {
489
            super.onPreExecute();
490
        }
491
 
492
        @Override
493
        protected String doInBackground(JSONObject... arg0) {
494
 
495
            try {
496
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<>();
497
                nameValuePairs.add(new BasicNameValuePair("pushdata", arg0[0].toString()));
498
                HttpClient httpclient = new DefaultHttpClient();
499
                HttpPost httppost = new HttpPost(apiData.getString("pollnotification.url.received", "http://45.79.106.95:3001/addPollNotification"));
500
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
501
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
502
                HttpResponse response = httpclient.execute(httppost);
503
                HttpEntity entity = response.getEntity();
504
            }
505
            catch (Exception e) {
506
                e.printStackTrace();
507
            }
508
            return "success";
509
        }
510
 
511
        @Override
512
        protected void onPostExecute(String result) {
513
            super.onPostExecute(result);
514
        }
515
    }
516
 
517
 
518
    public Bitmap getBitmapfromUrl(String imageUrl) {
519
        try {
520
            URL url = new URL(imageUrl);
521
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
522
            connection.setDoInput(true);
523
            connection.connect();
524
            InputStream input = connection.getInputStream();
525
            Bitmap bitmap = BitmapFactory.decodeStream(input);
526
            return bitmap;
527
        }
528
        catch (Exception e) {
529
            // TODO Auto-generated catch block
530
            e.printStackTrace();
531
            return null;
532
 
533
        }
534
    }
535
}