Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. JSONObject request=messageContent.getJSONObject("request");
  2. intent = new Intent(getApplicationContext(), NewRequest.class);
  3. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
  4. intent.putExtra(NewRequest.REQUEST, String.valueOf(request));
  5.  
  6. Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  7.  
  8.  
  9. PendingIntent pendingIntent = PendingIntent.getActivity(this, id, intent,
  10. PendingIntent.FLAG_UPDATE_CURRENT);
  11.  
  12. NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
  13. .setSmallIcon(R.mipmap.ic_launcher)
  14. .setContentText(body)
  15. .setContentTitle(title)
  16. .setAutoCancel(true)
  17. .setColor(ContextCompat.getColor(this, R.color.colorPrimary))
  18. .setVibrate(new long[] { 1000, 1000 })
  19. .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
  20. .setSound(defaultSoundUri)
  21. .setContentIntent(pendingIntent);
  22.  
  23. Notification notification = notificationBuilder.build();
  24. notification.defaults |= Notification.DEFAULT_VIBRATE;
  25. notification.defaults |= Notification.DEFAULT_SOUND;
  26.  
  27. NotificationManager notificationManager =
  28. (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  29.  
  30. PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
  31. PowerManager.WakeLock wl = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "My Tag");
  32. wl.acquire(10000);
  33.  
  34. notificationManager.notify(id, notification);
  35.  
  36. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
  37. stackBuilder.addParentStack(NewRequest.class);
  38. stackBuilder.addNextIntent(intent);
  39.  
  40. PendingIntent pendingIntent =
  41. stackBuilder.getPendingIntent(id, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement