List of usage examples for android.app Notification DEFAULT_VIBRATE
int DEFAULT_VIBRATE
To view the source code for android.app Notification DEFAULT_VIBRATE.
Click Source Link
From source file:com.onshift.mobile.ExternalReceiver.java
@Override public void onReceive(Context context, Intent intent) { myNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); int notificationCount = 1; Bundle extras = intent.getExtras();//from ww w . ja v a 2s . co m StringBuilder payload = new StringBuilder(); StringBuilder messagePayload = new StringBuilder(); StringBuilder message = new StringBuilder(); Gson gson = new Gson(); msgv1 = new PushNotificationMessage_v1(); msg = new PushNotificationMessage(); SharedPreferences settings = context.getSharedPreferences("mysettings", Context.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); String UserID = settings.getString("UserID", ""); Boolean registrationmsg = false; Boolean displayNotification = false; if (extras != null) { for (String key : extras.keySet()) { if (key.equals("registration_id")) { Log.i("key: ", key); Log.i("value: ", extras.getString(key)); payload.append(String.format("%s=%s", key, extras.getString(key)) + '\n'); MainActivity.sendRegistrationToWebview(extras.getString(key)); registrationmsg = true; } if (key.equals("error")) { registrationmsg = true; } if (extras.containsKey("message")) { if ((key.equals("message")) || (key.equals("message_type_id")) || (key.equals("shift_id")) || (key.equals("id")) || (key.equals("recipient_id")) || (key.equals("badge"))) { if (key.equals("message")) { message.append(String.format("%s", extras.getString(key))); msgv1.set_message(extras.getString(key)); } if (key.equals("message_type_id")) { msgv1.set_messagetypeid(extras.getString(key)); } if (key.equals("id")) { msgv1.set_messageid(extras.getString(key)); } if (key.equals("shift_id")) { msgv1.set_shiftid(extras.getString(key)); } if (key.equals("badge")) { msgv1.set_badge(extras.getString(key)); try { notificationCount = Integer.parseInt(extras.getString(key)); } catch (NumberFormatException nfe) { } } if (key.equals("recipient_id")) { if (extras.getString(key).equals(UserID)) { displayNotification = true; } } } } if (extras.containsKey("msg")) { if ((key.equals("msg")) || (key.equals("msg_type")) || (key.equals("id")) || (key.equals("rid")) || (key.equals("badge"))) { if (key.equals("msg")) { message.append(String.format("%s", extras.getString(key))); msg.set_message(extras.getString(key)); } if (key.equals("msg_type")) { msg.set_msgtype(extras.getString(key)); } if (key.equals("id")) { msg.set_messageid(extras.getString(key)); } if (key.equals("badge")) { msg.set_badge(extras.getString(key)); try { notificationCount = Integer.parseInt(extras.getString(key)); } catch (NumberFormatException nfe) { } } if (key.equals("rid")) { if (extras.getString(key).equals(UserID)) { displayNotification = true; } } } } } if (msgv1.get_message() != null) { messagePayload.append(gson.toJson(msgv1)); } if (msg.get_message() != null) { messagePayload.append(gson.toJson(msg)); } try { if (messagePayload.toString() != null) { if (!registrationmsg) { if (displayNotification) { MainActivity.sendForegroundNotificationToWebview(messagePayload.toString()); } } } } catch (Exception e) { } } if (notificationCount > 1) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("OnShift Mobile") .setContentText(String.valueOf(notificationCount) + MESSAGETEMPLATE) .setDefaults(Notification.DEFAULT_VIBRATE); // Intent resultIntent = new Intent(context, MainActivity.class); Intent resultIntent = new Intent(context, UniversalLoginActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); if (messagePayload.toString() != null) { resultIntent.putExtra("message", messagePayload.toString()); editor.putString("PendingMessage", messagePayload.toString()); editor.commit(); } // The stack builder object will contain an artificial back stack // for the // started Activity. // This ensures that navigating backward from the Activity leads out // of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(UniversalLoginActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. if (displayNotification) { mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } } else { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("OnShift Mobile").setContentText(message) .setDefaults(Notification.DEFAULT_VIBRATE); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, UniversalLoginActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); if (messagePayload.toString() != null) { resultIntent.putExtra("message", messagePayload.toString()); editor.putString("PendingMessage", messagePayload.toString()); editor.commit(); } TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(UniversalLoginActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (!registrationmsg) { if (displayNotification) { mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } } } }
From source file:de.tum.in.tumcampus.services.GcmIntentService.java
private void sendNotification(Bundle extras) { //Catch newer gcm messages which can be different from chat messages //Dismiss them for now if (extras.containsKey("payload") && extras.containsKey("type")) { return;// w w w. j a v a2s . c o m } //Get the update details int chatRoomId = Integer.parseInt(extras.getString("room")); int memberId = Integer.parseInt(extras.getString("member")); int messageId = -1; if (extras.containsKey("message")) { messageId = Integer.parseInt(extras.getString("message")); } Utils.logv( "Received GCM notification: room=" + chatRoomId + " member=" + memberId + " message=" + messageId); // Get the data necessary for the ChatActivity ChatMember member = Utils.getSetting(this, Const.CHAT_MEMBER, ChatMember.class); ChatRoom chatRoom = ChatClient.getInstance(this).getChatRoom(chatRoomId); ChatMessageManager manager = new ChatMessageManager(this, chatRoom.getId()); Cursor messages = manager.getNewMessages(this.getPrivateKeyFromSharedPrefs(), member, messageId); // Notify any open chat activity that a message has been received Intent intent = new Intent("chat-message-received"); intent.putExtras(extras); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); //Check if chat is currently open then don't show a notification if it is if (ChatActivity.mCurrentOpenChatRoom != null && chatRoomId == ChatActivity.mCurrentOpenChatRoom.getId()) { return; } String txt = null; if (messages.moveToFirst()) { do { if (txt == null) txt = messages.getString(3); else txt += "\n" + messages.getString(3); } while (messages.moveToNext()); } // Put the data into the intent Intent notificationIntent = new Intent(this, ChatActivity.class); notificationIntent.putExtra(Const.CURRENT_CHAT_ROOM, new Gson().toJson(chatRoom)); TaskStackBuilder sBuilder = TaskStackBuilder.create(this); sBuilder.addNextIntent(new Intent(this, MainActivity.class)); sBuilder.addNextIntent(new Intent(this, ChatRoomsActivity.class)); sBuilder.addNextIntent(notificationIntent); if (Utils.getSettingBool(this, "card_chat_phone", true) && messageId == -1) { PendingIntent contentIntent = sBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); // Notification sound Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.message); String replyLabel = getResources().getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(ChatActivity.EXTRA_VOICE_REPLY).setLabel(replyLabel) .build(); // Create the reply action and add the remote input NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_reply, getString(R.string.reply_label), contentIntent).addRemoteInput(remoteInput).build(); //Show a nice notification Notification notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.tum_logo_notification).setContentTitle(chatRoom.getName().substring(4)) .setStyle(new NotificationCompat.BigTextStyle().bigText(txt)).setContentText(txt) .setContentIntent(contentIntent).setDefaults(Notification.DEFAULT_VIBRATE) .setLights(0xff0000ff, 500, 500).setSound(sound).setAutoCancel(true) .extend(new NotificationCompat.WearableExtender().addAction(action)).build(); NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(chatRoomId << 4 + NOTIFICATION_ID, notification); } }
From source file:com.nanostuffs.yurdriver.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w ww .j a va 2 s . c o m*/ private void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MapActivity.class); notificationIntent.putExtra("fromNotification", "notification"); // 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, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; System.out.println("notification====>" + message); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; // notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0x00000000; notification.ledOnMS = 0; notification.ledOffMS = 0; notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock"); wakeLock.acquire(); wakeLock.release(); }
From source file:com.aylanetworks.aura.GcmIntentService.java
private void sendNotification(String msg, String sound) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); // Find the launcher class for our application PackageManager pm = getPackageManager(); String packageName = getPackageName(); Intent query = new Intent(Intent.ACTION_MAIN); Class launcherClass = null;/* w w w . ja v a 2 s .co m*/ query.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> foundIntents = pm.queryIntentActivities(query, 0); for (ResolveInfo info : foundIntents) { if (TextUtils.equals(info.activityInfo.packageName, packageName)) { launcherClass = info.activityInfo.getClass(); } } if (launcherClass == null) { Log.e(TAG, "Could not find application launcher class"); return; } Intent appIntent = new Intent(this, launcherClass); // main activity of Ayla Control/aMCA PendingIntent contentIntent = PendingIntent.getActivity(this, 0, appIntent, 0); //Determine the sound to be played Uri soundUri = null; if (sound == null) { // NOP //PushNotification.playSound("bdth.mp3"); } else if (sound.equals("none")) { // NOP } else if (sound.equals("default")) { soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // TYPE_NOTIFICATION or TYPE_ALARM } else if (sound.equals("alarm")) { soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); // TYPE_NOTIFICATION or TYPE_ALARM } else { boolean playedSound; playedSound = PushNotification.playSound(sound); if (playedSound == false) { soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // TYPE_NOTIFICATION or TYPE_ALARM } } // @formatter:off NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) //.setSound(soundUri) .setSmallIcon(R.drawable.ic_push_icon).setContentTitle(getResources().getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setLights(0xFFff0000, 500, 500) // flashing red light .setContentText(msg).setAutoCancel(true) //.setPriority(Notification.FLAG_HIGH_PRIORITY) .setDefaults(Notification.DEFAULT_VIBRATE | Notification.FLAG_SHOW_LIGHTS); // @formatter:on if (soundUri != null) { mBuilder.setSound(soundUri); } mBuilder.setPriority(PRIORITY_MAX); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.nobledesignlabs.lookupaddress.GcmIntentService.java
private void displayNotification(Context context, Bundle extras) { // ---PendingIntent to launch activity if the user selects // this notification--- // NotificationView context = new NotificationView(); try {//ww w.j a v a 2 s.c o m Intent i = null; Random rand = new Random(); int timenow = rand.nextInt(); String title = extras.getString("title"); String message = extras.getString("message"); String picture = extras.getString("imgurl"); String sinfotype = extras.getString("infotype"); boolean cancelonclick = true; int infotype = Integer.parseInt(sinfotype); if (infotype == CommonStuff.ADDRESS_NOTIFICATION) { i = new Intent(context, NotificationView.class); i.putExtra("notificationID", timenow); i.putExtra("message", message); i.putExtra("title", title); i.putExtra("picture", picture); cancelonclick = true; // i.putExtra("infotype", picture); } else if (infotype == CommonStuff.ADDRESS_AUTHORIZATION_REQUEST) { i = new Intent(context, AuthorizationRequestActivity.class); String token = extras.getString("token"); i.putExtra("notificationID", timenow); i.putExtra("message", message); i.putExtra("title", title); i.putExtra("picture", picture); i.putExtra("token", token); String address = extras.getString("address"); i.putExtra("address", address); cancelonclick = true; // i.putExtra("infotype", picture); } else if (infotype == CommonStuff.ADDRESS_SHARING_REQUEST) { i = new Intent(context, AuthorizedActivity.class); i.putExtra("notificationID", timenow); i.putExtra("message", message); i.putExtra("title", title); String token = extras.getString("token"); String address = extras.getString("address"); i.putExtra("address", address); i.putExtra("token", token); cancelonclick = false; // i.putExtra("infotype", picture); } if (i != null) { i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, timenow, i, 0); /* * NotificationManager nm = (NotificationManager) context * .getSystemService(Context.NOTIFICATION_SERVICE); Notification * notif = new Notification( R.drawable.direction_uturn, * message, timenow); // String title = * context.getString(R.string.app_name); * * i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | * Intent.FLAG_ACTIVITY_SINGLE_TOP); * * notif.setLatestEventInfo(context, title, message, * pendingIntent); // notif.flags |= * Notification.FLAG_AUTO_CANCEL; notif.flags = * Notification.FLAG_AUTO_CANCEL; notif.defaults |= * Notification.DEFAULT_SOUND; notif.defaults |= * Notification.DEFAULT_VIBRATE; notif.vibrate = new long[] { * 100, 250, 100, 500 }; nm.notify(timenow, notif); */ NotificationCompat.Builder b = new NotificationCompat.Builder(context); if (cancelonclick) { b.setAutoCancel(true).setOngoing(false).setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.direction_uturn).setTicker(title).setContentTitle(title) .setContentText(message).setVibrate(new long[] { 100, 250, 100, 500 }) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setContentIntent(pendingIntent).setLights(0xFFF7BF05, 250, 500) .setContentInfo("me@address"); } else { b.setAutoCancel(false).setOngoing(true).setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.direction_uturn).setTicker(title).setContentTitle(title) .setContentText(message).setLights(0xFF308036, 250, 500) .setVibrate(new long[] { 100, 250, 100, 500 }) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setContentIntent(pendingIntent).setContentInfo("me@address"); } NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(timenow, b.build()); } } catch (Exception d) { } }
From source file:com.NotifyMe.GcmIntentService.java
private void sendNotificationWithExtras(Bundle extras) { String message = extras.getString("message"); String service = extras.getString("service"); String type = extras.getString("type"); String title = "NotifyMe [" + service + "]"; mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent;/*from w ww .j a v a 2s. c o m*/ if (service.equals("Reddit")) { Intent resultIntent = new Intent(Intent.ACTION_VIEW); String url = "http://reddit.com"; if (type.equals("reddit-front-page")) { if (Integer.parseInt(extras.getString("count")) == 1) { try { JSONArray posts = new JSONArray(extras.getString("links")); url = posts.getJSONObject(0).getString("url"); message = posts.getJSONObject(0).getString("title"); } catch (JSONException e) { url = "http://reddit.com"; } } else { url = "http://reddit.com"; } } else if (type.equals("user-comment") || type.equals("user-submission")) { url = extras.getString("link"); } resultIntent.setData(Uri.parse(url)); contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else if (service.equals("weather")) { Intent resultIntent; Intent weatherIntent = getWeatherAppIntent(); if (weatherIntent != null) { resultIntent = weatherIntent; } else { resultIntent = new Intent(Intent.ACTION_VIEW); String url = "http://weather.com/"; resultIntent.setData(Uri.parse(url)); } contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else if (service.equals("poly")) { Intent resultIntent = new Intent(Intent.ACTION_VIEW); String url = "https://www4.polymtl.ca/poly/poly.html"; resultIntent.setData(Uri.parse(url)); contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else if (service.equals("github")) { Intent resultIntent = new Intent(Intent.ACTION_VIEW); String url = extras.getString("link"); resultIntent.setData(Uri.parse(url)); contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else { contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(title).setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message) .setDefaults(Notification.DEFAULT_VIBRATE).setOnlyAlertOnce(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void refreshNotification(Context context, boolean noTimeline) { AppSettings settings = AppSettings.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int currentAccount = sharedPrefs.getInt("current_account", 1); //int[] unreadCounts = new int[] {4, 1, 2}; // for testing int[] unreadCounts = getUnreads(context); int timeline = unreadCounts[0]; int realTimelineCount = timeline; // if they don't want that type of notification, simply set it to zero if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) { unreadCounts[0] = 0;/*from w w w .java 2 s . c o m*/ } if (!settings.mentionsNot) { unreadCounts[1] = 0; } if (!settings.dmsNot) { unreadCounts[2] = 0; } if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) { } else { Intent markRead = new Intent(context, MarkReadService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); String shortText = getShortText(unreadCounts, context, currentAccount); String longText = getLongText(unreadCounts, context, currentAccount); // [0] is the full title and [1] is the screenname String[] title = getTitle(unreadCounts, context, currentAccount); boolean useExpanded = useExp(context); boolean addButton = addBtn(unreadCounts); if (title == null) { return; } Intent resultIntent; if (unreadCounts[1] != 0 && unreadCounts[0] == 0) { // it is a mention notification (could also have a direct message) resultIntent = new Intent(context, RedirectToMentions.class); } else { resultIntent = new Intent(context, MaterialMainActivity.class); } PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0]) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)) .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1])) .setContentIntent(resultPendingIntent).setAutoCancel(true) .setTicker(TweetLinkUtils.removeColorHtml(shortText, settings)) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) { // inbox style notification for mentions mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // inbox style notification for direct messages mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else { // big text style for an unread count on timeline, mentions, and direct messages mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title[0], shortText); } // Light Flow notification sendToLightFlow(context, title[0], shortText); int homeTweets = unreadCounts[0]; int mentionsTweets = unreadCounts[1]; int dmTweets = unreadCounts[2]; int newC = 0; if (homeTweets > 0) { newC++; } if (mentionsTweets > 0) { newC++; } if (dmTweets > 0) { newC++; } if (settings.notifications && newC > 0) { if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); if (addButton) { // the reply and read button should be shown Log.v("username_for_noti", title[1]); sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit(); MentionsDataSource data = MentionsDataSource.getInstance(context); long id = data.getLastIds(currentAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, null, 0); sharedPrefs.edit().putLong("from_notification_long", id).commit(); sharedPrefs.edit() .putString("from_notification_text", "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings)) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel("@" + title[1] + " ").build(); // Create the notification action NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build(); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending); mBuilder.addAction(replyAction); mBuilder.addAction(action.build()); } // Build the notification and issues it with notification manager. notificationManager.notify(1, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } } // if there are unread tweets on the timeline, check them for favorite users if (settings.favoriteUserNotifications && realTimelineCount > 0) { favUsersNotification(currentAccount, context); } } try { ContentValues cv = new ContentValues(); cv.put("tag", "com.daiv.android.twitter/com.daiv.android.twitter.ui.MainActivity"); // add the direct messages and mentions cv.put("count", unreadCounts[1] + unreadCounts[2]); context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv); } catch (IllegalArgumentException ex) { /* Fine, TeslaUnread is not installed. */ } catch (Exception ex) { /* Some other error, possibly because the format of the ContentValues are incorrect. Log but do not crash over this. */ ex.printStackTrace(); } }
From source file:com.juick.android.XMPPMessageReceiver.java
public static void updateInfo(final Context context, int nMessages, boolean silent) { final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); String tickerText = "juick: new message"; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); // public Notification(int icon, java.lang.CharSequence tickerText, long when) { /* compiled code */ } // Notification notif = new Notification(R.drawable.juick_message_icon, null,System.currentTimeMillis()); int iconIndex; if (nMessages < 1) { iconIndex = 0; // to prevent out of bounds } else if (nMessages > NOTIFICATION_ICONS.length - 1) { iconIndex = NOTIFICATION_ICONS.length - 1; // to prevent out of bounds } else {//ww w. jav a2 s . c om iconIndex = nMessages; } boolean showNumberUnread = sp.getBoolean("show_number_unread", true); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setSmallIcon( showNumberUnread ? NOTIFICATION_ICONS[iconIndex] : R.drawable.juick_message_icon_plain) .setWhen(System.currentTimeMillis()); //context.getResources().getDrawable(smallIcon) // public Notification(int icon, java.lang.CharSequence tickerText, long when) { /* compiled code */ } int notification = 0; if (!silent) { if (sp.getBoolean("led_enabled", true)) notification |= Notification.DEFAULT_LIGHTS; if (System.currentTimeMillis() - lastVibrate > 5000) { // add some sound if (sp.getBoolean("vibration_enabled", true)) notification |= Notification.DEFAULT_VIBRATE; if (sp.getBoolean("ringtone_enabled", true)) { String ringtone_uri = sp.getString("ringtone_uri", ""); if (ringtone_uri.length() > 0) { notificationBuilder.setSound(Uri.parse(ringtone_uri)); } else notification |= Notification.DEFAULT_SOUND; } lastVibrate = System.currentTimeMillis(); } } notificationBuilder.setDefaults(silent ? 0 : notification); Intent intent = new Intent(context, XMPPService.class); intent.setAction(XMPPService.ACTION_LAUNCH_MESSAGELIST); PendingIntent pendingIntent = PendingIntent.getService(context, 1000, intent, 0); //PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, nintent, 0); notificationBuilder.setContentTitle("Juick: " + nMessages + " new message" + (nMessages > 1 ? "s" : "")) .setContentText(tickerText).setContentIntent(pendingIntent).setNumber(nMessages); nm.notify("", 2, notificationBuilder.getNotification()); }
From source file:de.hackerspacebremen.push.PushIntentService.java
public void displayNotification(final Context context, final SpaceData data, final boolean vibrationEnabled, final boolean permanentNotification) throws JSONException { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); final boolean permanent = permanentNotification && data.isSpaceOpen(); String timeString = context.getString(R.string.unknown); Date time = data.getTime();//from w ww . jav a 2 s . co m if (time != null) { timeString = SpeakingDateFormat.format(time); } int icon; CharSequence notificationText; final CharSequence contentTitle; if (data.isSpaceOpen()) { icon = R.drawable.notification_open; notificationText = context.getString(R.string.space_open, timeString); contentTitle = context.getString(R.string.space_open_simple); } else { icon = R.drawable.notification_closed; notificationText = context.getString(R.string.space_closed, timeString); contentTitle = context.getString(R.string.space_closed_simple); } long when = System.currentTimeMillis(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(icon); builder.setTicker(notificationText); builder.setWhen(when); if (data.getMessage() != null && data.getMessage().length() > 0) { builder.setStyle(new NotificationCompat.BigTextStyle().setSummaryText(notificationText) .bigText("Nachricht: \n" + data.getMessage())); } if (!permanent) { builder.setAutoCancel(true); } builder.setContentTitle(contentTitle); builder.setContentText(notificationText); Intent notificationIntent = new Intent(context, StartActivity.class); notificationIntent.putExtra("status_json", SpaceDataJsonParser.parse(data).toString()); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); builder.setContentIntent(contentIntent); final Notification notification = builder.build(); if (vibrationEnabled) { notification.defaults |= Notification.DEFAULT_VIBRATE; } if (permanent) { notification.flags |= Notification.FLAG_ONGOING_EVENT; } mNotificationManager.notify(Constants.NOTIFICATION_ID, notification); }
From source file:ru.glesik.wifireminders.AlarmService.java
public void showReminder(String title, String text) { SharedPreferences sharedPrefSettings = PreferenceManager.getDefaultSharedPreferences(this); boolean vibrate = sharedPrefSettings.getBoolean("prefVibrate", true); String sound = sharedPrefSettings.getString("prefRingtone", "default"); Uri soundURI = Uri.parse(sound);/* w w w. java 2 s . c o m*/ NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); int icon; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // Icon for Android 3.0+. icon = R.drawable.notify; } else { // Icon for Android 2.3 and lower. icon = R.drawable.notify_legacy; } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(icon) .setContentTitle(title).setContentText(text) //.setVibrate(pattern) .setSound(soundURI).setDefaults( // Notification.DEFAULT_SOUND // | Notification.DEFAULT_VIBRATE Notification.DEFAULT_LIGHTS) .setPriority(NotificationCompat.PRIORITY_HIGH).setOnlyAlertOnce(true); Intent ni = new Intent(this, RemindersListActivity.class); ni.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, ni, 0); mBuilder.setContentIntent(pi); mBuilder.setAutoCancel(true); Notification notification = mBuilder.build(); if (vibrate) { notification.defaults |= Notification.DEFAULT_VIBRATE; } // Displaying notification with random id, in case there will be more. mNotificationManager.notify((int) (Math.random() * ((999) + 1)), notification); }