Subversion Repositories SmartDukaan

Rev

Rev 21480 | Rev 22835 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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