Guest User

Untitled

a guest
Apr 25th, 2014
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. protected void onMessage(Context context, Intent intent) {
  2. Log.i(TAG, "Received message");
  3. String message = intent.getExtras().getString("message");
  4. String ids = intent.getExtras().getString("registration_ids");
  5. takedata=message;
  6. WindowManager window = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
  7. Display display = window.getDefaultDisplay();
  8. int width = display.getWidth();
  9. height = display.getHeight();
  10.  
  11. displayMessage(context, message);
  12. // notifies user
  13. generateNotification(context, message);
  14. }
  15.  
  16.  
  17. ///原本用的方法
  18. // private void generateNotification(Context context, String message) {
  19. // int icon=R.drawable.icon_notification;
  20. // //顯示在狀態列的文字
  21. // long when = System.currentTimeMillis();
  22. // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  23. // Notification notification = new Notification(icon, message, when);
  24. // Intent notificationIntent = new Intent(context, Activity_login.class);
  25. // Log.w("START","WYH");
  26. // // set intent so it does not start a new activity
  27. // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
  28. // | Intent.FLAG_ACTIVITY_SINGLE_TOP);
  29. // PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  30. // notification.setLatestEventInfo(context, "你有新的資訊", "點我查看", intent);
  31. // // Play default notification sound
  32. // notification.defaults |= Notification.DEFAULT_SOUND;
  33. // // Vibrate if vibrate is enabled
  34. // notification.defaults |= Notification.DEFAULT_VIBRATE;
  35. // notification.flags |= Notification.FLAG_AUTO_CANCEL;
  36. // notificationManager.notify(0, notification);
  37. // }
  38.  
  39.  
  40. private void generateNotification(Context context, String message) {
  41. int icon=R.drawable.icon_notification;
  42. //顯示在狀態列的文字
  43. long when = System.currentTimeMillis();
  44. NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  45. Notification notification = new Notification(icon, message, when);
  46. PendingIntent pIntent = PendingIntent.getActivity(this,0,new Intent(this, over.class),PendingIntent.FLAG_UPDATE_CURRENT);
  47. // Play default notification sound
  48. notification.defaults |= Notification.DEFAULT_SOUND;
  49. // Vibrate if vibrate is enabled
  50. notification.defaults |= Notification.DEFAULT_VIBRATE;
  51. notification.flags |= Notification.FLAG_AUTO_CANCEL;
  52. notification.setLatestEventInfo(this,"你有新資訊", "點我查看",pIntent);
  53. nManager.notify(0, notification);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment