| Line 1... |
Line 1... |
| 1 |
package com.saholic.profittill;
|
1 |
package com.saholic.profittill;
|
| 2 |
|
2 |
|
| - |
|
3 |
import android.app.Notification;
|
| - |
|
4 |
import android.app.NotificationChannel;
|
| 3 |
import android.app.NotificationManager;
|
5 |
import android.app.NotificationManager;
|
| 4 |
import android.app.PendingIntent;
|
6 |
import android.app.PendingIntent;
|
| 5 |
import android.content.Context;
|
7 |
import android.content.Context;
|
| 6 |
import android.content.Intent;
|
8 |
import android.content.Intent;
|
| 7 |
import android.content.SharedPreferences;
|
9 |
import android.content.SharedPreferences;
|
| 8 |
import android.graphics.Bitmap;
|
10 |
import android.graphics.Bitmap;
|
| 9 |
import android.graphics.BitmapFactory;
|
11 |
import android.graphics.BitmapFactory;
|
| - |
|
12 |
import android.graphics.Color;
|
| 10 |
import android.media.RingtoneManager;
|
13 |
import android.media.RingtoneManager;
|
| 11 |
import android.net.Uri;
|
14 |
import android.net.Uri;
|
| 12 |
import android.os.AsyncTask;
|
15 |
import android.os.AsyncTask;
|
| 13 |
import android.os.Build;
|
16 |
import android.os.Build;
|
| 14 |
import android.os.Bundle;
|
17 |
import android.os.Bundle;
|
| Line 65... |
Line 68... |
| 65 |
private NotificationManager mNotificationManager;
|
68 |
private NotificationManager mNotificationManager;
|
| 66 |
NotificationCompat.Builder builder;
|
69 |
NotificationCompat.Builder builder;
|
| 67 |
SharedPreferences notificationData;
|
70 |
SharedPreferences notificationData;
|
| 68 |
SharedPreferences.Editor notificationDataEditor;
|
71 |
SharedPreferences.Editor notificationDataEditor;
|
| 69 |
private static final String TAG = "MyFirebaseMsgService";
|
72 |
private static final String TAG = "MyFirebaseMsgService";
|
| - |
|
73 |
String channelId = "123";
|
| - |
|
74 |
CharSequence channelName = "SmartDukaan";
|
| 70 |
Intent intent;
|
75 |
Intent intent;
|
| 71 |
Bitmap bitmap;
|
76 |
Bitmap bitmap;
|
| 72 |
|
77 |
|
| 73 |
@Override
|
78 |
@Override
|
| 74 |
public void onMessageReceived(RemoteMessage remoteMessage) {
|
79 |
public void onMessageReceived(RemoteMessage remoteMessage) {
|
| - |
|
80 |
super.onMessageReceived(remoteMessage);
|
| 75 |
userData = this.getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
81 |
userData = this.getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
| 76 |
apiData = this.getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
82 |
apiData = this.getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
| 77 |
userDataEditor = userData.edit();
|
83 |
userDataEditor = userData.edit();
|
| 78 |
apiSettingsEditor = apiData.edit();
|
84 |
apiSettingsEditor = apiData.edit();
|
| 79 |
notificationData = this.getSharedPreferences("Notification_Data", Context.MODE_PRIVATE);
|
85 |
notificationData = this.getSharedPreferences("Notification_Data", Context.MODE_PRIVATE);
|
| Line 92... |
Line 98... |
| 92 |
String campaignUserId = data.get("url").split("user_id=")[1];
|
98 |
String campaignUserId = data.get("url").split("user_id=")[1];
|
| 93 |
if (userData.getString("id", "0").equalsIgnoreCase(campaignUserId)) {
|
99 |
if (userData.getString("id", "0").equalsIgnoreCase(campaignUserId)) {
|
| 94 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
100 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
| 95 |
AnalyticsUtility.getAnalyticsRequest(getApplicationContext(), userData.getString("id", ""), "Notification", "Check Expiry", data.get("cid") + ""),
|
101 |
AnalyticsUtility.getAnalyticsRequest(getApplicationContext(), userData.getString("id", ""), "Notification", "Check Expiry", data.get("cid") + ""),
|
| 96 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
102 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
| - |
|
103 |
|
| 97 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getApplicationContext());
|
104 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getApplicationContext());
|
| 98 |
new CheckNotificationExpiry().execute(data);
|
105 |
new CheckNotificationExpiry().execute(data);
|
| 99 |
}
|
106 |
}
|
| 100 |
|
107 |
|
| 101 |
|
108 |
|
| Line 262... |
Line 269... |
| 262 |
}
|
269 |
}
|
| 263 |
}
|
270 |
}
|
| 264 |
}
|
271 |
}
|
| 265 |
PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, resultIntent, 0);
|
272 |
PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, resultIntent, 0);
|
| 266 |
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
273 |
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
| 267 |
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.pmlauncher);
|
274 |
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.notification);
|
| 268 |
if (image==null) {
|
275 |
if (image==null) {
|
| - |
|
276 |
|
| - |
|
277 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
| - |
|
278 |
|
| - |
|
279 |
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName,
|
| - |
|
280 |
NotificationManager.IMPORTANCE_HIGH);
|
| - |
|
281 |
notificationChannel.enableLights(true);
|
| - |
|
282 |
notificationChannel.setLightColor(Color.RED);
|
| - |
|
283 |
notificationChannel.enableVibration(true);
|
| - |
|
284 |
notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
|
| - |
|
285 |
mNotificationManager.createNotificationChannel(notificationChannel);
|
| - |
|
286 |
Notification.Builder mBuilder = new Notification.Builder(this, channelId);
|
| - |
|
287 |
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
| - |
|
288 |
mBuilder.setSmallIcon(R.drawable.sdnotifictation);
|
| - |
|
289 |
} else{
|
| - |
|
290 |
mBuilder.setSmallIcon(R.drawable.transpaentnavigation);
|
| - |
|
291 |
}
|
| - |
|
292 |
mBuilder.setContentTitle(title);
|
| - |
|
293 |
mBuilder.setStyle(new Notification.BigTextStyle().bigText(msg));
|
| - |
|
294 |
mBuilder.setContentText(msg);
|
| - |
|
295 |
mBuilder.setLargeIcon(bm);
|
| - |
|
296 |
mBuilder.setAutoCancel(true);
|
| - |
|
297 |
mBuilder.setContentIntent(contentIntent);
|
| - |
|
298 |
mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build());
|
| - |
|
299 |
}
|
| - |
|
300 |
else {
|
| 269 |
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
|
301 |
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
|
| 270 |
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
302 |
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
| 271 |
mBuilder.setSmallIcon(R.drawable.navigation_bar);
|
303 |
mBuilder.setSmallIcon(R.drawable.sdnotifictation);
|
| 272 |
} else{
|
304 |
} else {
|
| 273 |
mBuilder.setSmallIcon(R.drawable.pmnotification3);
|
305 |
mBuilder.setSmallIcon(R.drawable.transpaentnavigation);
|
| - |
|
306 |
}
|
| - |
|
307 |
mBuilder.setContentTitle(title);
|
| - |
|
308 |
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
|
| - |
|
309 |
mBuilder.setContentText(msg);
|
| - |
|
310 |
mBuilder.setLargeIcon(bm);
|
| - |
|
311 |
mBuilder.setAutoCancel(true);
|
| - |
|
312 |
mBuilder.setSound(Uri.parse("android.resource://"
|
| - |
|
313 |
+ getBaseContext().getPackageName() + "/" + R.raw.slow));
|
| - |
|
314 |
mBuilder.setContentIntent(contentIntent);
|
| - |
|
315 |
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
|
| 274 |
}
|
316 |
}
|
| 275 |
mBuilder.setContentTitle(title);
|
- |
|
| 276 |
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
|
- |
|
| 277 |
mBuilder.setContentText(msg);
|
- |
|
| 278 |
mBuilder.setLargeIcon(bm);
|
- |
|
| 279 |
mBuilder.setAutoCancel(true);
|
- |
|
| 280 |
mBuilder.setSound(alarmSound);
|
- |
|
| 281 |
mBuilder.setContentIntent(contentIntent);
|
- |
|
| 282 |
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
|
- |
|
| 283 |
} else {
|
317 |
} else {
|
| - |
|
318 |
|
| - |
|
319 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
| - |
|
320 |
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName,
|
| - |
|
321 |
NotificationManager.IMPORTANCE_HIGH);
|
| - |
|
322 |
notificationChannel.enableLights(true);
|
| - |
|
323 |
notificationChannel.setLightColor(Color.RED);
|
| - |
|
324 |
notificationChannel.enableVibration(true);
|
| - |
|
325 |
notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
|
| - |
|
326 |
mNotificationManager.createNotificationChannel(notificationChannel);
|
| 284 |
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
|
327 |
Notification.Builder mBuilder = new Notification.Builder(this, channelId);
|
| 285 |
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
328 |
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
| 286 |
mBuilder.setSmallIcon(R.drawable.navigation_bar);
|
329 |
mBuilder.setSmallIcon(R.drawable.sdnotifictation);
|
| - |
|
330 |
} else {
|
| - |
|
331 |
mBuilder.setSmallIcon(R.drawable.transpaentnavigation);
|
| - |
|
332 |
}
|
| - |
|
333 |
mBuilder.setContentTitle(title);
|
| - |
|
334 |
mBuilder.setStyle(new Notification.BigTextStyle().bigText(msg));
|
| - |
|
335 |
mBuilder.setStyle(new Notification.BigPictureStyle().bigPicture(image));
|
| - |
|
336 |
mBuilder.setContentText(msg);
|
| - |
|
337 |
mBuilder.setLargeIcon(bm);
|
| - |
|
338 |
mBuilder.setAutoCancel(true);
|
| - |
|
339 |
mBuilder.setContentIntent(contentIntent);
|
| - |
|
340 |
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
|
| 287 |
} else{
|
341 |
} else {
|
| - |
|
342 |
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
|
| - |
|
343 |
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
| 288 |
mBuilder.setSmallIcon(R.drawable.pmnotification3);
|
344 |
mBuilder.setSmallIcon(R.drawable.sdnotifictation);
|
| - |
|
345 |
} else {
|
| - |
|
346 |
mBuilder.setSmallIcon(R.drawable.transpaentnavigation);
|
| - |
|
347 |
}
|
| - |
|
348 |
mBuilder.setContentTitle(title);
|
| - |
|
349 |
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
|
| - |
|
350 |
mBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(image));
|
| - |
|
351 |
mBuilder.setContentText(msg);
|
| - |
|
352 |
mBuilder.setLargeIcon(bm);
|
| - |
|
353 |
mBuilder.setAutoCancel(true);
|
| - |
|
354 |
mBuilder.setSound(alarmSound);
|
| - |
|
355 |
mBuilder.setContentIntent(contentIntent);
|
| - |
|
356 |
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
|
| 289 |
}
|
357 |
}
|
| 290 |
mBuilder.setContentTitle(title);
|
- |
|
| 291 |
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
|
- |
|
| 292 |
mBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(image));
|
- |
|
| 293 |
mBuilder.setContentText(msg);
|
- |
|
| 294 |
mBuilder.setLargeIcon(bm);
|
- |
|
| 295 |
mBuilder.setAutoCancel(true);
|
- |
|
| 296 |
mBuilder.setSound(alarmSound);
|
- |
|
| 297 |
mBuilder.setContentIntent(contentIntent);
|
- |
|
| 298 |
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
|
- |
|
| 299 |
}
|
- |
|
| 300 |
|
358 |
|
| - |
|
359 |
}
|
| 301 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
360 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
| 302 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
361 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
| 303 |
t.send(new HitBuilders.EventBuilder()
|
362 |
t.send(new HitBuilders.EventBuilder()
|
| 304 |
.setCategory("Notification")
|
363 |
.setCategory("Notification")
|
| 305 |
.setAction("Building Notification for campaign Id " + cid)
|
364 |
.setAction("Building Notification for campaign Id " + cid)
|
| Line 348... |
Line 407... |
| 348 |
httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
|
407 |
httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
|
| 349 |
HttpResponse response = httpclient.execute(httppost);
|
408 |
HttpResponse response = httpclient.execute(httppost);
|
| 350 |
HttpEntity entity = response.getEntity();
|
409 |
HttpEntity entity = response.getEntity();
|
| 351 |
int status = response.getStatusLine().getStatusCode();
|
410 |
int status = response.getStatusLine().getStatusCode();
|
| 352 |
nameValuePairsGcm.clear();
|
411 |
nameValuePairsGcm.clear();
|
| - |
|
412 |
}
|
| 353 |
} catch (Exception e) {
|
413 |
catch (Exception e) {
|
| - |
|
414 |
|
| 354 |
}
|
415 |
}
|
| 355 |
return "success";
|
416 |
return "success";
|
| 356 |
}
|
417 |
}
|
| 357 |
|
418 |
|
| 358 |
@Override
|
419 |
@Override
|
| Line 363... |
Line 424... |
| 363 |
|
424 |
|
| 364 |
public void sendNotificationByPolling(JSONArray objects,Context c) {
|
425 |
public void sendNotificationByPolling(JSONArray objects,Context c) {
|
| 365 |
userData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
426 |
userData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
| 366 |
apiData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
427 |
apiData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
| 367 |
notificationData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("Notification_Data", Context.MODE_PRIVATE);
|
428 |
notificationData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("Notification_Data", Context.MODE_PRIVATE);
|
| 368 |
userDataEditor = userData.edit();
|
429 |
userDataEditor = userData.edit();
|
| 369 |
apiSettingsEditor = apiData.edit();
|
430 |
apiSettingsEditor = apiData.edit();
|
| 370 |
notificationDataEditor = notificationData.edit();
|
431 |
notificationDataEditor = notificationData.edit();
|
| 371 |
|
432 |
|
| 372 |
Bundle bundle;
|
433 |
Bundle bundle;
|
| 373 |
|
434 |
|
| Line 473... |
Line 534... |
| 473 |
}
|
534 |
}
|
| 474 |
}
|
535 |
}
|
| 475 |
}
|
536 |
}
|
| 476 |
PendingIntent contentIntent = PendingIntent.getActivity(GoogleAnalyticsTracker.getAppContext(), NOTIFICATION_ID, resultIntent, 0);
|
537 |
PendingIntent contentIntent = PendingIntent.getActivity(GoogleAnalyticsTracker.getAppContext(), NOTIFICATION_ID, resultIntent, 0);
|
| 477 |
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
538 |
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
| 478 |
Bitmap bm = BitmapFactory.decodeResource(GoogleAnalyticsTracker.getAppContext().getResources(), R.drawable.pmlauncher);
|
539 |
Bitmap bm = BitmapFactory.decodeResource(GoogleAnalyticsTracker.getAppContext().getResources(), R.drawable.notification);
|
| 479 |
if (bitmap==null) {
|
540 |
if (bitmap==null) {
|
| 480 |
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
541 |
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
| 481 |
c )
|
542 |
c );
|
| - |
|
543 |
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
| 482 |
.setSmallIcon(R.drawable.navigation_bar)
|
544 |
mBuilder.setSmallIcon(R.drawable.sdnotifictation);
|
| - |
|
545 |
} else {
|
| - |
|
546 |
mBuilder.setSmallIcon(R.drawable.transpaentnavigation);
|
| - |
|
547 |
}
|
| 483 |
.setContentTitle(title)
|
548 |
mBuilder .setContentTitle(title);
|
| 484 |
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
|
549 |
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
|
| 485 |
.setContentText(msg)
|
550 |
mBuilder.setContentText(msg);
|
| 486 |
.setLargeIcon(bm)
|
551 |
mBuilder .setLargeIcon(bm);
|
| 487 |
.setAutoCancel(true)
|
552 |
mBuilder.setAutoCancel(true);
|
| 488 |
.setSound(alarmSound);
|
553 |
mBuilder .setSound(alarmSound);
|
| 489 |
mBuilder.setContentIntent(contentIntent);
|
554 |
mBuilder.setContentIntent(contentIntent);
|
| 490 |
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
|
555 |
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
|
| 491 |
}
|
556 |
}
|
| 492 |
|
557 |
|
| 493 |
else {
|
558 |
else {
|
| 494 |
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
559 |
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
| 495 |
GoogleAnalyticsTracker.getAppContext())
|
560 |
GoogleAnalyticsTracker.getAppContext());
|
| - |
|
561 |
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
| 496 |
.setSmallIcon(R.drawable.pmnotification3)
|
562 |
mBuilder.setSmallIcon(R.drawable.sdnotifictation);
|
| - |
|
563 |
} else {
|
| - |
|
564 |
mBuilder.setSmallIcon(R.drawable.transpaentnavigation);
|
| - |
|
565 |
}
|
| 497 |
.setContentTitle(title)
|
566 |
mBuilder.setContentTitle(title);
|
| 498 |
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
|
567 |
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
|
| 499 |
.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap))
|
568 |
mBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap));
|
| 500 |
.setContentText(msg)
|
569 |
mBuilder.setContentText(msg);
|
| 501 |
.setLargeIcon(bm)
|
570 |
mBuilder.setLargeIcon(bm);
|
| 502 |
.setAutoCancel(true)
|
571 |
mBuilder.setAutoCancel(true);
|
| 503 |
.setSound(alarmSound);
|
572 |
mBuilder.setSound(alarmSound);
|
| 504 |
mBuilder.setContentIntent(contentIntent);
|
573 |
mBuilder.setContentIntent(contentIntent);
|
| 505 |
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
|
574 |
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
|
| 506 |
}
|
575 |
}
|
| 507 |
++NOTIFICATION_ID;
|
576 |
++NOTIFICATION_ID;
|
| 508 |
JSONObject data = new JSONObject();
|
577 |
JSONObject data = new JSONObject();
|