List of usage examples for android.app PendingIntent FLAG_ONE_SHOT
int FLAG_ONE_SHOT
To view the source code for android.app PendingIntent FLAG_ONE_SHOT.
Click Source Link
From source file:com.wizardsofm.deskclock.data.TimerNotificationBuilderN.java
@Override public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) { final Timer timer = unexpired.get(0); final int count = unexpired.size(); // Compute some values required below. final boolean running = timer.isRunning(); final Resources res = context.getResources(); final long base = getChronometerBase(timer); final String pname = context.getPackageName(); final RemoteViews content = new RemoteViews(pname, com.wizardsofm.deskclock.R.layout.chronometer_notif_content); content.setChronometerCountDown(com.wizardsofm.deskclock.R.id.chronometer, true); content.setChronometer(com.wizardsofm.deskclock.R.id.chronometer, base, null, running); final List<Notification.Action> actions = new ArrayList<>(2); final CharSequence stateText; if (count == 1) { if (running) { // Single timer is running. if (TextUtils.isEmpty(timer.getLabel())) { stateText = res.getString(com.wizardsofm.deskclock.R.string.timer_notification_label); } else { stateText = timer.getLabel(); }/*w ww . j a va 2 s . c o m*/ // Left button: Pause final Intent pause = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_pause_24dp); final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.timer_pause); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right Button: +1 Minute final Intent addMinute = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon2 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_add_24dp); final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.timer_plus_1_min); final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } else { // Single timer is paused. stateText = res.getString(com.wizardsofm.deskclock.R.string.timer_paused); // Left button: Start final Intent start = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_start_24dp); final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.sw_resume_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right Button: Reset final Intent reset = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon2 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_reset_24dp); final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } } else { if (running) { // At least one timer is running. stateText = res.getString(com.wizardsofm.deskclock.R.string.timers_in_use, count); } else { // All timers are paused. stateText = res.getString(com.wizardsofm.deskclock.R.string.timers_stopped, count); } final Intent reset = TimerService.createResetUnexpiredTimersIntent(context); final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_reset_24dp); final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.timer_reset_all); final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); } content.setTextViewText(com.wizardsofm.deskclock.R.id.state, stateText); // Intent to load the app and show the timer when the notification is tapped. final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, com.wizardsofm.deskclock.R.string.label_notification); final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false) .setAutoCancel(false).setCustomContentView(content).setContentIntent(pendingShowApp) .setPriority(Notification.PRIORITY_HIGH).setCategory(Notification.CATEGORY_ALARM) .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_timer) .setGroup(nm.getTimerNotificationGroupKey()).setVisibility(Notification.VISIBILITY_PUBLIC) .setStyle(new Notification.DecoratedCustomViewStyle()) .setActions(actions.toArray(new Notification.Action[actions.size()])) .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background)) .build(); }
From source file:com.example.android.notifyme.MainActivity.java
/** * OnClick method for the "Update Me!" button. Updates the existing notification to show a * picture./*from w w w . j a v a 2 s . c om*/ */ private void updateNotification() { //Load the drawable resource into the a bitmap image Bitmap androidImage = BitmapFactory.decodeResource(getResources(), R.drawable.mascot_1); //Sets up the pending intent that is delivered when the notification is clicked Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Sets up the pending intent to cancel the notification, // delivered when the user dismisses the notification Intent cancelIntent = new Intent(ACTION_CANCEL_NOTIFICATION); PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(this, NOTIFICATION_ID, cancelIntent, PendingIntent.FLAG_ONE_SHOT); //Sets up the pending intent associated with the Learn More notification action, //uses an implicit intent to go to the web. Intent learnMoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(NOTIFICATION_GUIDE_URL)); PendingIntent learnMorePendingIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, learnMoreIntent, PendingIntent.FLAG_ONE_SHOT); //Build the updated notification NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.notification_title)) .setContentText(getString(R.string.notification_text)).setSmallIcon(R.drawable.ic_android) .setContentIntent(notificationPendingIntent).setPriority(NotificationCompat.PRIORITY_DEFAULT) .setDefaults(NotificationCompat.DEFAULT_ALL).setDeleteIntent(cancelPendingIntent) .addAction(R.drawable.ic_learn_more, getString(R.string.learn_more), learnMorePendingIntent) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(androidImage) .setBigContentTitle(getString(R.string.notification_updated))); //Disable the update button, leaving only the option to cancel mNotifyButton.setEnabled(false); mUpdateButton.setEnabled(false); mCancelButton.setEnabled(true); //Deliver the notification Notification myNotification = notifyBuilder.build(); mNotifyManager.notify(NOTIFICATION_ID, myNotification); }
From source file:com.example.khalid.sharektest.Utils.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param dataPayLoad FCM message body received. */// www. j a v a2 s. c om private void sendNotification(JSONObject dataPayLoad) { try { if (dataPayLoad.get("type").equals("proposal")) { intent = new Intent(this, MyProfile.class); } else if (dataPayLoad.get("type").equals("proposal-reaction")) { intent = new Intent(this, NotificationActivity.class); String stringObject = dataPayLoad.toString(); intent.putExtra("data", stringObject); } else { intent = new Intent(this, HomePage.class); } intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon2).setContentTitle("Sharek") .setContentText(dataPayLoad.getString("body")).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); } catch (JSONException e) { e.printStackTrace(); } }
From source file:graaby.app.wallet.services.GcmIntentService.java
private void sendNotification(final String msg) { try {//from w w w.j a v a2s . c o m JSONObject object = new JSONObject(msg); PendingIntent pendingIntent = null; String notificationTitle, smallContentText, smallContentInfo = ""; int notificationImageResource = R.drawable.ic_noty_point, notificationID, uniquePendingId = (int) (System.currentTimeMillis() & 0xfffffff); SharedPreferences pref = getSharedPreferences("pref_notification", Activity.MODE_PRIVATE); Uri noty_sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (!TextUtils.isEmpty(pref.getString("notifications_new_message_ringtone", ""))) { noty_sound = Uri.parse(pref.getString("notifications_new_message_ringtone", "")); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSound(noty_sound) .setLights(0xff2ECC71, 300, 1000).setAutoCancel(Boolean.TRUE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_SOCIAL); if (pref.getBoolean("notifications_new_message_vibrate", true)) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } Intent activityIntent = new Intent(); switch (NotificationType.getType(object.getInt(getString(R.string.field_gcm_msg_type)))) { case SHARE_POINTS: //user received points from contact String sender = object.getString(getString(R.string.field_gcm_name)); int amount = object.getInt(getString(R.string.contact_send_amount)); notificationTitle = getString(R.string.gcm_message_recieved_points); smallContentText = String.format(getString(R.string.gcm_message_recieved_points_content), sender, amount); smallContentInfo = String.valueOf(amount); notificationImageResource = R.drawable.ic_noty_point; notificationID = getRandomInt(0, 50); mBuilder.setColor(getResources().getColor(R.color.alizarin)); activityIntent.setClass(this, PointReceivedActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_POINTS); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(PointReceivedActivity.class); stackBuilder.addNextIntent(activityIntent); Intent broadcastIntent = new Intent(this, GraabyBroadcastReceiver.class); broadcastIntent.setAction(GraabyBroadcastReceiver.ACTION_THANK); broadcastIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); broadcastIntent.putExtra(Helper.NOTIFICATIONID, notificationID); PendingIntent pendingBroadcastIntent = PendingIntent.getBroadcast(this, uniquePendingId, broadcastIntent, 0); mBuilder.addAction(R.drawable.ic_action_accept, "Say thanks", pendingBroadcastIntent); pendingIntent = stackBuilder.getPendingIntent(uniquePendingId, PendingIntent.FLAG_ONE_SHOT); break; case TRANSACTION: //user made a transaction amount = object.getInt(getString(R.string.contact_send_amount)); String outlet = object.getString(getString(R.string.field_business_name)); notificationTitle = getString(R.string.gcm_message_transaction); smallContentText = String.format(getString(R.string.gcm_message_transaction_content), amount, outlet); smallContentInfo = String.valueOf(amount); notificationImageResource = R.drawable.ic_noty_point; notificationID = getRandomInt(51, 100); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(smallContentText)); mBuilder.setColor(getResources().getColor(R.color.alizarin)); activityIntent.setClass(this, PointReceivedActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_TX); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); activityIntent.putExtra(Helper.NOTIFICATIONID, notificationID); pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_ONE_SHOT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_STATUS); break; case NEW_VOUCHER: //new marketplace voucher has appeared outlet = object.getString(getString(R.string.field_business_name)); notificationTitle = getString(R.string.gcm_message_market); if (object.has("msg")) smallContentText = object.getString("msg") + " @ " + outlet; else smallContentText = String.format(getString(R.string.gcm_message_market_content), outlet); smallContentInfo = ""; notificationImageResource = R.drawable.ic_gcm_discount; notificationID = NOTIFICATION_ID_NEW_MARKET; mBuilder.setStyle(new NotificationCompat.BigTextStyle() .bigText(String.format(getString(R.string.gcm_message_market_content), outlet))); mBuilder.setColor(getResources().getColor(R.color.sunflower)); activityIntent.setClass(this, MarketActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_NEW_DISCOUNT); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); activityIntent.putExtra(Helper.NOTIFICATIONID, NOTIFICATION_ID_NEW_MARKET); activityIntent.putExtra(Helper.MY_DISCOUNT_ITEMS_FLAG, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_PROMO); break; case NEW_FEED: notificationTitle = "New message"; smallContentText = object.getString("msg"); notificationImageResource = R.drawable.ic_noty_announcement; notificationID = NOTIFICATION_ID_FEED; activityIntent.setClass(this, FeedActivity.class); activityIntent.putExtra(Helper.NOTIFICATIONID, NOTIFICATION_ID_FEED); activityIntent.setAction(NOTIFICATION_ACTION_FEED); mBuilder.setColor(getResources().getColor(R.color.alizarin)); pendingIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(activityIntent) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); break; case THANK_CONTACT: //contact thanks you for sending points String thanksString = object.getString(getString(R.string.field_gcm_name)); notificationTitle = getString(R.string.gcm_message_thanked); smallContentText = String.format(getString(R.string.gcm_message_thanked_small_content), thanksString); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(smallContentText)); notificationImageResource = R.drawable.ic_noty_thank; notificationID = NOTIFICATION_ID_THANKED; mBuilder.setColor(getResources().getColor(R.color.belizehole)); break; case CHECKIN: //checkin notification outlet = object.getString(getString(R.string.field_gcm_name)); notificationTitle = getString(R.string.gcm_message_checkin_title); smallContentText = String.format(getString(R.string.gcm_message_checkin_small_content), outlet); notificationImageResource = R.drawable.ic_gcm_checkin; notificationID = NOTIFICATION_ID_CHECKIN; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_STATUS); mBuilder.setColor(getResources().getColor(R.color.wisteria)); break; case INFO_NEEDED: notificationTitle = getString(R.string.gcm_message_meta_info_title); smallContentText = getString(R.string.gcm_message_meta_info_title); notificationImageResource = R.drawable.ic_noty_information; notificationID = NOTIFICATION_ID_INFO; mBuilder.setColor(getResources().getColor(R.color.emarald)); activityIntent.setClass(this, ExtraInfoActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_INFO); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); activityIntent.putExtra(Helper.NOTIFICATIONID, notificationID); pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); break; case NONE: default: notificationTitle = ""; smallContentText = ""; smallContentInfo = ""; notificationID = 0; } if (pendingIntent == null) pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), notificationImageResource)) .setSmallIcon(R.drawable.ic_noty_graaby).setContentTitle(notificationTitle) .setContentText(smallContentText).setContentInfo(smallContentInfo) .setContentIntent(pendingIntent); mNotificationManager.notify(notificationID, mBuilder.build()); } catch (JSONException e) { e.printStackTrace(); } }
From source file:at.maui.cheapcast.service.CheapCastService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(LOG_TAG, "onStartCommand()"); Notification n = null;/*from w ww. j a v a 2 s . c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Notification.Builder mBuilder = new Notification.Builder(this).setSmallIcon(R.drawable.ic_service) .setContentTitle("CheapCast").setContentText("Service enabled.").setOngoing(true) .addAction(R.drawable.ic_reload, getString(R.string.restart_service), PendingIntent.getBroadcast(this, 1, new Intent(Const.ACTION_RESTART), PendingIntent.FLAG_ONE_SHOT)) .addAction(R.drawable.ic_stop, getString(R.string.stop_service), PendingIntent .getBroadcast(this, 2, new Intent(Const.ACTION_STOP), PendingIntent.FLAG_ONE_SHOT)); Intent i = new Intent(this, PreferenceActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); mBuilder.setContentIntent(pi); n = mBuilder.build(); } else { Intent i = new Intent(this, PreferenceActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_service).setContentTitle("CheapCast") .setContentText("Service enabled.").setOngoing(true).setContentIntent(pi); n = mBuilder.getNotification(); } startForeground(1337, n); if (!mRunning) initService(); return START_STICKY; }
From source file:com.franmontiel.fcmnotificationhandler.RemoteMessageToNotificationMapper.java
private PendingIntent createNotificationPendingItent(RemoteMessage remoteMessage) { return PendingIntent.getActivity(context, remoteMessage.getMessageId().hashCode(), createNotificationIntent(remoteMessage), PendingIntent.FLAG_ONE_SHOT); }
From source file:com.app.easyblood.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), com.app.easyblood.R.drawable.logo_notif); if (intType == 2) { Intent question = new Intent(this, MainActivity.class); question.putExtra("type", "Replies"); question.putExtra("askedby", askedby); question.putExtra("userid_questions", userid_questions); question.putExtra("questionmessage", questionmessage); question.putExtra("asked_time_questions", asked_time_questions); question.putExtra("imagepath", imagepath); question.putExtra("Category", category); question.putExtra("questionid", questionid); question.putExtra("userprofession_questions", userprofession_questions); PendingIntent contentIntent = PendingIntent.getActivity(this, Integer.parseInt(questionid), question, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(com.app.easyblood.R.drawable.logo_notif).setLargeIcon(bitmap) .setContentTitle("New Answer") .setStyle(new NotificationCompat.BigTextStyle().bigText(repliedby + " says " + replymessage)) .setContentText(repliedby + " says " + replymessage).setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (intType == 3) { Intent requestIntent = new Intent(this, MainActivity.class); requestIntent.putExtra("type", "request"); requestIntent.putExtra("NotificationRequestId", requestId); PendingIntent contentIntent = PendingIntent.getActivity(this, Integer.parseInt(requestId), requestIntent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(com.app.easyblood.R.drawable.logo_notif).setLargeIcon(bitmap) .setContentTitle("New Request") .setStyle(new NotificationCompat.BigTextStyle().bigText(username + " : " + message)) .setContentText(username + " : " + message).setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (intType == 4) { Intent responseIntent = new Intent(this, MainActivity.class); responseIntent.putExtra("type", "response"); responseIntent.putExtra("NotificationResponseId", responseId); responseIntent.putExtra("NotificationRequestId", requestId); responseIntent.putExtra("NotificationResponseUserId", userId); responseIntent.putExtra("NotificationResponseUserName", username); responseIntent.putExtra("NotificationResponseMessage", message); responseIntent.putExtra("NotificationResponseUserProfession", responseUserProfession); responseIntent.putExtra("NotificationResponseUserProfilePhotoServerPath", responseUserProfilePath); PendingIntent contentIntent = PendingIntent.getActivity(this, Integer.parseInt(responseId), responseIntent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(com.app.easyblood.R.drawable.logo_notif).setContentTitle("New Response") .setLargeIcon(bitmap)//w w w .j av a2 s .co m .setStyle(new NotificationCompat.BigTextStyle().bigText(username + " : " + message)) .setContentText(username + " : " + message).setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (intType == 5) { Intent chatIntent = new Intent(getApplicationContext(), ChatActivity.class); chatIntent.putExtra("ChatId", chatChatId); chatIntent.putExtra("Message", chatMessage); chatIntent.putExtra("SentOn", chatMessageTime); chatIntent.putExtra("SenderId", chatSenderId); chatIntent.putExtra("UserName", chatSenderName); chatIntent.putExtra("received", true); ChatIdMap chatIdMap = new ChatIdMap(); chatIdMap.chatId = chatChatId; chatIdMap.userId = chatSenderId; chatIdMap.userName = chatSenderName; ChatIdMapDBHandler.InsertChatIdMap(getApplicationContext(), chatIdMap); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), Integer.parseInt(chatChatId), chatIntent, PendingIntent.FLAG_ONE_SHOT); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); String time = dateFormat.format(date); time = time.substring(11, time.lastIndexOf(':')); ChatInfo newMessage = new ChatInfo(); newMessage.setMessage(chatMessage); newMessage.setSentBy(false); newMessage.setTimeStamp(time); newMessage.setChatId(chatChatId); ChatInfoDBHandler.InsertChatInfo(getApplicationContext(), newMessage); if (TempDataClass.alreadyAdded == true) { TempDataClass.alreadyAdded = false; return; } Notification mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(com.app.easyblood.R.drawable.logo_notif).setLargeIcon(bitmap) .setContentTitle("Chat Notification").setContentIntent(pendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(chatSenderName + ":" + chatMessage)) .setContentText(chatSenderName + ":" + chatMessage).setAutoCancel(true).build(); mNotificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(NOTIFICATION_ID, mBuilder); } else { } }
From source file:com.monkey.entonado.MainActivity.java
/** * OnResume/* ww w .j a va 2 s . c o m*/ * register the broadcast receiver with the intent values to be matched */ @Override protected void onResume() { super.onResume(); registerReceiver(mReceiver, mIntentFilter); CountDownTimer t = new CountDownTimer(1000, 500) { public void onTick(long millisUntilFinished) { } public void onFinish() { if (intentoConectar) { mostrarMensaje(mensajeConexion); intentoConectar = false; } else if (intentoEnviarLista) { String mensaje = ""; boolean entro = false; if (mensajeConexion == null) { mensaje = "Estas desconectado"; } else if (mensajeConexion.equals("desconectado")) { mensaje = "Estas desconectado"; } else if (mensajeConexion.equals("Estas conectado!")) { mensaje = "La lista ha sido enviada"; Intent in = new Intent(MainActivity.this, AlarmReciever.class); PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, in, PendingIntent.FLAG_ONE_SHOT); entro = true; System.out.println("puso alarma"); AlarmManager am = (AlarmManager) MainActivity.this.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000 * 60, pi); } else { mensaje = mensajeConexion; } if (!entro) mostrarMensaje(mensaje); intentoEnviarLista = false; } } }.start(); }
From source file:gwind.windalarm.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from w w w . j a v a 2 s . c o m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.logo).setContentTitle("GWindAlarm").setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:kr.ds.travel.MyGcmListenerService.java
private void sendNotification(String message, Bitmap bitmap, String push_type) { Intent intent = new Intent(this, IntroActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("type", push_type); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder; if (isvibrate) { notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.push_icon) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); } else {// www . j ava 2s . c o m notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.push_icon) .setContentText(message).setAutoCancel(true).setVibrate(new long[] { 0 }) .setContentIntent(pendingIntent); } if (bitmap != null) { NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle(); style.setBigContentTitle(getString(R.string.app_name)); style.setSummaryText(message); style.bigPicture(bitmap); notificationBuilder.setStyle(style); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(UniqueID.getRandomNumber(1000), notificationBuilder.build()); }