Guest User

Untitled

a guest
Dec 16th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. if (Objects.equals(intent.getAction(), IZIGaapsConstants.ACTION.STARTFOREGROUND_ACTION)) {
  2.  
  3. Intent deviceLockCheck = new Intent(this, IZIGaapsForegroundNotification.class);
  4. deviceLockCheck .setAction(IZIGaapsConst.LOCK_START);
  5. PendingIntent preStartIntent = PendingIntent.getService(this, 0, deviceLockCheck , 0);
  6. NotificationCompat.Action startIt = new NotificationCompat.Action(R.drawable.ic_start_24dp,
  7. getString(R.string.screen_notification_action_start), precordStartIntent);
  8. startNotificationForeGround(createRecordingNotification(startIt).build(), IZIGaapsConst.DEVICE_LOCK_NOTIFICATION_ID);
  9.  
  10. }else if (intent.getAction().equals(IZIGaapsConstants.ACTION.STOPFOREGROUND_ACTION)){
  11.  
  12. stopForeground(true);
  13. stopSelf();
  14.  
  15. }
  16.  
  17.  
  18.  
  19. if (Objects.equals(intent.getAction(), IZIGaapsConst.LOCK_START)) {
  20.  
  21. //i want the lock event to be start from here to check for devecie lock and unlock
  22.  
  23. } else if (Objects.equals(intent.getAction(), IZIGaapsConst.LOCK_STOP)) {
  24.  
  25. //you know the task :)
  26. }
  27.  
  28. return START_STICKY;
  29. }
  30.  
  31. private NotificationCompat.Builder createRecordingNotification(NotificationCompat.Action action) {
  32.  
  33. Bitmap icon = BitmapFactory.decodeResource(getResources(),
  34. R.drawable.rec_icon);
  35. NotificationCompat.Builder notification = new NotificationCompat.Builder(this, IZIGaapsConst.RECORDING_NOTIFICATION_CHANNEL_ID)
  36. .setContentTitle(getResources().getString(R.string.screen_recording_notification_title))
  37. .setTicker(getResources().getString(R.string.screen_recording_notification_title))
  38. .setSmallIcon(R.drawable.rec_icon)
  39. .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false))
  40. .setPriority(Notification.PRIORITY_MIN);
  41. if (action != null)
  42. notification.addAction(action);
  43. return notification;
  44. }
  45.  
  46. private void startNotificationForeGround(Notification notification, int ID) {
  47. startForeground(ID, notification);
  48. }
Add Comment
Please, Sign In to add comment