Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void onMessage(Context context, Intent intent) {
- Log.i(TAG, "Received message");
- String message = intent.getExtras().getString("message");
- String ids = intent.getExtras().getString("registration_ids");
- takedata=message;
- WindowManager window = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
- Display display = window.getDefaultDisplay();
- int width = display.getWidth();
- height = display.getHeight();
- displayMessage(context, message);
- // notifies user
- generateNotification(context, message);
- }
- ///原本用的方法
- // private void generateNotification(Context context, String message) {
- // int icon=R.drawable.icon_notification;
- // //顯示在狀態列的文字
- // long when = System.currentTimeMillis();
- // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- // Notification notification = new Notification(icon, message, when);
- // Intent notificationIntent = new Intent(context, Activity_login.class);
- // Log.w("START","WYH");
- // // set intent so it does not start a new activity
- // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
- // | Intent.FLAG_ACTIVITY_SINGLE_TOP);
- // PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
- // notification.setLatestEventInfo(context, "你有新的資訊", "點我查看", intent);
- // // Play default notification sound
- // notification.defaults |= Notification.DEFAULT_SOUND;
- // // Vibrate if vibrate is enabled
- // notification.defaults |= Notification.DEFAULT_VIBRATE;
- // notification.flags |= Notification.FLAG_AUTO_CANCEL;
- // notificationManager.notify(0, notification);
- // }
- private void generateNotification(Context context, String message) {
- int icon=R.drawable.icon_notification;
- //顯示在狀態列的文字
- long when = System.currentTimeMillis();
- NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- Notification notification = new Notification(icon, message, when);
- PendingIntent pIntent = PendingIntent.getActivity(this,0,new Intent(this, over.class),PendingIntent.FLAG_UPDATE_CURRENT);
- // Play default notification sound
- notification.defaults |= Notification.DEFAULT_SOUND;
- // Vibrate if vibrate is enabled
- notification.defaults |= Notification.DEFAULT_VIBRATE;
- notification.flags |= Notification.FLAG_AUTO_CANCEL;
- notification.setLatestEventInfo(this,"你有新資訊", "點我查看",pIntent);
- nManager.notify(0, notification);
- }
Advertisement
Add Comment
Please, Sign In to add comment