List of usage examples for android.app PendingIntent getActivity
public static PendingIntent getActivity(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:com.roamprocess1.roaming4world.syncadapter.SyncAdapter.java
private void showNotification(String count, String number_date, int j) { // Notification notification = new Notification(R.drawable.r4wlogowhitefill,count, System.currentTimeMillis()); Intent in = new Intent(mcontext, SipHome.class); in.putExtra("MissedCall", true); PendingIntent contentIntent = PendingIntent.getActivity(mcontext, 0, in, PendingIntent.FLAG_CANCEL_CURRENT); // notification.setLatestEventInfo(mcontext, count, number_date, contentIntent); Notification notification = new NotificationCompat.Builder(mcontext).setContentTitle(count) .setContentText(number_date).setSmallIcon(R.drawable.r4wlogowhitefill) // .setGroup(GROUP_KEY_MISSEDCALLS) .setContentIntent(contentIntent).build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(j, notification); }
From source file:br.com.arlsoft.pushclient.PushClientModule.java
public static void sendNotification(Bundle extras) { if (extras == null || extras.isEmpty()) return;//w w w . java2 s. co m TiApplication appContext = TiApplication.getInstance(); int appIconId = appContext.getResources().getIdentifier("appicon", "drawable", appContext.getPackageName()); String appName = appContext.getAppInfo().getName(); Bundle extrasRoot = extras; int badgeCount = -1; int notificationId = 0; String notificationTitle = null; String notificationText = null; String notificationTicker = null; Uri notificationSound = null; int notificationDefaults = 0; // TEXT if (extras.containsKey("text")) { notificationText = extras.getString("text"); } else if (extras.containsKey("alert")) { notificationText = extras.getString("alert"); } else if (extras.containsKey("message")) { notificationText = extras.getString("message"); } else if (extras.containsKey("data")) { try { JSONObject reader = new JSONObject(extras.getString("data")); Bundle newExtras = new Bundle(); for (int i = 0; i < reader.names().length(); i++) { String key = reader.names().getString(i); newExtras.putString(key, reader.getString(key)); } if (newExtras.containsKey("text")) { notificationText = newExtras.getString("text"); extras = newExtras; } else if (newExtras.containsKey("alert")) { notificationText = newExtras.getString("alert"); extras = newExtras; } else if (newExtras.containsKey("message")) { notificationText = newExtras.getString("message"); extras = newExtras; } } catch (JSONException e) { String text = extras.getString("data"); if (text != null) { notificationText = text; } } } else if (extras.containsKey("msg")) { try { JSONObject reader = new JSONObject(extras.getString("msg")); Bundle newExtras = new Bundle(); for (int i = 0; i < reader.names().length(); i++) { String key = reader.names().getString(i); newExtras.putString(key, reader.getString(key)); } if (newExtras.containsKey("text")) { notificationText = newExtras.getString("text"); extras = newExtras; } else if (newExtras.containsKey("alert")) { notificationText = newExtras.getString("alert"); extras = newExtras; } else if (newExtras.containsKey("message")) { notificationText = newExtras.getString("message"); extras = newExtras; } } catch (JSONException e) { String text = extras.getString("msg"); if (text != null) { notificationText = text; } } } else if (extras.containsKey("default")) { try { JSONObject reader = new JSONObject(extras.getString("default")); Bundle newExtras = new Bundle(); for (int i = 0; i < reader.names().length(); i++) { String key = reader.names().getString(i); newExtras.putString(key, reader.getString(key)); } if (newExtras.containsKey("text")) { notificationText = newExtras.getString("text"); extras = newExtras; } else if (newExtras.containsKey("alert")) { notificationText = newExtras.getString("alert"); extras = newExtras; } else if (newExtras.containsKey("message")) { notificationText = newExtras.getString("message"); extras = newExtras; } } catch (JSONException e) { String text = extras.getString("default"); if (text != null) { notificationText = text; } } } else if (extras.containsKey("payload")) { try { JSONObject reader = new JSONObject(extras.getString("payload")); Bundle newExtras = new Bundle(); for (int i = 0; i < reader.names().length(); i++) { String key = reader.names().getString(i); newExtras.putString(key, reader.getString(key)); } if (newExtras.containsKey("text")) { notificationText = newExtras.getString("text"); extras = newExtras; } else if (newExtras.containsKey("alert")) { notificationText = newExtras.getString("alert"); extras = newExtras; } else if (newExtras.containsKey("message")) { notificationText = newExtras.getString("message"); extras = newExtras; } } catch (JSONException e) { String text = extras.getString("payload"); if (text != null) { notificationText = text; } } } // TITLE if (extras.containsKey("title")) { notificationTitle = extras.getString("title"); } else { notificationTitle = appName; } // TICKER if (extras.containsKey("ticker")) { notificationTicker = extras.getString("ticker"); } else { notificationTicker = notificationText; } // SOUND if (extras.containsKey("sound")) { if (extras.getString("sound").equalsIgnoreCase("default")) { notificationDefaults |= Notification.DEFAULT_SOUND; } else { File file = null; // getResourcesDirectory file = new File("app://" + extras.getString("sound")); if (file != null && file.exists()) { notificationSound = Uri.fromFile(file); } else { // getResourcesDirectory + sound folder file = new File("app://sound/" + extras.getString("sound")); if (file != null && file.exists()) { notificationSound = Uri.fromFile(file); } else { // getExternalStorageDirectory file = new File("appdata://" + extras.getString("sound")); if (file != null && file.exists()) { notificationSound = Uri.fromFile(file); } else { // getExternalStorageDirectory + sound folder file = new File("appdata://sound/" + extras.getString("sound")); if (file != null && file.exists()) { notificationSound = Uri.fromFile(file); } else { // res folder int soundId = appContext.getResources().getIdentifier(extras.getString("sound"), "raw", appContext.getPackageName()); if (soundId != 0) { notificationSound = Uri.parse("android.resource://" + appContext.getPackageName() + "/raw/" + soundId); } else { // res folder without file extension String soundFile = extras.getString("sound").split("\\.")[0]; soundId = appContext.getResources().getIdentifier(soundFile, "raw", appContext.getPackageName()); if (soundId != 0) { notificationSound = Uri.parse("android.resource://" + appContext.getPackageName() + "/raw/" + soundId); } } } } } } } } else if (extrasRoot.containsKey("sound")) { if (extrasRoot.getString("sound").equalsIgnoreCase("default")) { notificationDefaults |= Notification.DEFAULT_SOUND; } else { File file = null; // getResourcesDirectory file = new File("app://" + extrasRoot.getString("sound")); if (file != null && file.exists()) { notificationSound = Uri.fromFile(file); } else { // getResourcesDirectory + sound folder file = new File("app://sound/" + extrasRoot.getString("sound")); if (file != null && file.exists()) { notificationSound = Uri.fromFile(file); } else { // getExternalStorageDirectory file = new File("appdata://" + extrasRoot.getString("sound")); if (file != null && file.exists()) { notificationSound = Uri.fromFile(file); } else { // getExternalStorageDirectory + sound folder file = new File("appdata://sound/" + extrasRoot.getString("sound")); if (file != null && file.exists()) { notificationSound = Uri.fromFile(file); } else { // res folder int soundId = appContext.getResources().getIdentifier(extrasRoot.getString("sound"), "raw", appContext.getPackageName()); if (soundId != 0) { notificationSound = Uri.parse("android.resource://" + appContext.getPackageName() + "/raw/" + soundId); } else { // res folder without file extension String soundFile = extrasRoot.getString("sound").split("\\.")[0]; soundId = appContext.getResources().getIdentifier(soundFile, "raw", appContext.getPackageName()); if (soundId != 0) { notificationSound = Uri.parse("android.resource://" + appContext.getPackageName() + "/raw/" + soundId); } } } } } } } } // VIBRATE if (extras.containsKey("vibrate") && extras.getString("vibrate").equalsIgnoreCase("true")) { notificationDefaults |= Notification.DEFAULT_VIBRATE; } // LIGHTS if (extras.containsKey("lights") && extras.getString("lights").equalsIgnoreCase("true")) { notificationDefaults |= Notification.DEFAULT_LIGHTS; } // NOTIFICATION ID if (extras.containsKey("notificationId")) { try { notificationId = Integer.parseInt(extras.getString("notificationId")); } catch (NumberFormatException nfe) { } } if (notificationId == 0) { notificationId = appContext.getAppProperties().getInt(PROPERTY_NOTIFICATION_ID, 0); notificationId++; appContext.getAppProperties().setInt(PROPERTY_NOTIFICATION_ID, notificationId); } // BADGE if (extras.containsKey("badge")) { try { badgeCount = Integer.parseInt(extras.getString("badge")); } catch (NumberFormatException nfe) { } } // LARGE ICON Bitmap largeIcon = null; if (extras.containsKey("largeIcon")) { largeIcon = getBitmap(extras.getString("largeIcon")); } else if (extras.containsKey("licon")) { largeIcon = getBitmap(extras.getString("licon")); } else if (extrasRoot.containsKey("largeIcon")) { largeIcon = getBitmap(extrasRoot.getString("largeIcon")); } else if (extrasRoot.containsKey("licon")) { largeIcon = getBitmap(extrasRoot.getString("licon")); } // SMALL ICON if (extras.containsKey("smallIcon")) { appIconId = appContext.getResources().getIdentifier(extras.getString("smallIcon"), "drawable", appContext.getPackageName()); if (appIconId == 0) { Log.i(TAG, "Unable to find resource identifier to custom smallIcon : " + extras.getString("smallIcon")); } } else if (extras.containsKey("sicon")) { appIconId = appContext.getResources().getIdentifier(extras.getString("sicon"), "drawable", appContext.getPackageName()); if (appIconId == 0) { Log.i(TAG, "Unable to find resource identifier to custom sicon : " + extras.getString("sicon")); } } else if (extrasRoot.containsKey("smallIcon")) { appIconId = appContext.getResources().getIdentifier(extrasRoot.getString("smallIcon"), "drawable", appContext.getPackageName()); if (appIconId == 0) { Log.i(TAG, "Unable to find resource identifier to custom smallIcon : " + extrasRoot.getString("smallIcon")); } } else if (extrasRoot.containsKey("sicon")) { appIconId = appContext.getResources().getIdentifier(extrasRoot.getString("sicon"), "drawable", appContext.getPackageName()); if (appIconId == 0) { Log.i(TAG, "Unable to find resource identifier to custom smallIcon : " + extrasRoot.getString("sicon")); } } if (notificationText != null) { // Intent launch = getLauncherIntent(extras); Intent launch = new Intent(appContext, PendingNotificationActivity.class); launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); if (extrasRoot != null && !extrasRoot.isEmpty()) { launch.putExtra(PROPERTY_EXTRAS, extrasRoot); } launch.setAction("dummy_unique_action_identifyer:" + notificationId); PendingIntent contentIntent = PendingIntent.getActivity(appContext, 0, launch, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(appContext); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText)); mBuilder.setContentText(notificationText); if (notificationTitle != null) { mBuilder.setContentTitle(notificationTitle); } if (notificationTicker != null) { mBuilder.setTicker(notificationTicker); } if (notificationDefaults != 0) { mBuilder.setDefaults(notificationDefaults); } if (notificationSound != null) { mBuilder.setSound(notificationSound); } if (badgeCount >= 0) { mBuilder.setNumber(badgeCount); } if (largeIcon != null) { mBuilder.setLargeIcon(largeIcon); } if (appIconId == 0) { appIconId = appContext.getResources().getIdentifier("appicon", "drawable", appContext.getPackageName()); } mBuilder.setSmallIcon(appIconId); mBuilder.setContentIntent(contentIntent); mBuilder.setAutoCancel(true); mBuilder.setWhen(System.currentTimeMillis()); // ledARGB, ledOnMS, ledOffMS boolean customLight = false; int argb = 0xFFFFFFFF; int onMs = 1000; int offMs = 2000; if (extras.containsKey("ledARGB")) { try { argb = TiColorHelper.parseColor(extras.getString("ledARGB")); customLight = true; } catch (Exception ex) { try { argb = Integer.parseInt(extras.getString("ledARGB")); customLight = true; } catch (NumberFormatException nfe) { } } } else if (extras.containsKey("ledc")) { try { argb = TiColorHelper.parseColor(extras.getString("ledc")); customLight = true; } catch (Exception ex) { try { argb = Integer.parseInt(extras.getString("ledc")); customLight = true; } catch (NumberFormatException nfe) { } } } else if (extrasRoot.containsKey("ledARGB")) { try { argb = TiColorHelper.parseColor(extrasRoot.getString("ledARGB")); customLight = true; } catch (Exception ex) { try { argb = Integer.parseInt(extrasRoot.getString("ledARGB")); customLight = true; } catch (NumberFormatException nfe) { } } } else if (extrasRoot.containsKey("ledc")) { try { argb = TiColorHelper.parseColor(extrasRoot.getString("ledc")); customLight = true; } catch (Exception ex) { try { argb = Integer.parseInt(extrasRoot.getString("ledc")); customLight = true; } catch (NumberFormatException nfe) { } } } if (extras.containsKey("ledOnMS")) { try { onMs = Integer.parseInt(extras.getString("ledOnMS")); customLight = true; } catch (NumberFormatException nfe) { } } if (extras.containsKey("ledOffMS")) { try { offMs = Integer.parseInt(extras.getString("ledOffMS")); customLight = true; } catch (NumberFormatException nfe) { } } if (customLight) { mBuilder.setLights(argb, onMs, offMs); } //Visibility if (extras.containsKey("visibility")) { try { mBuilder.setVisibility(Integer.parseInt(extras.getString("visibility"))); } catch (NumberFormatException nfe) { } } else if (extras.containsKey("vis")) { try { mBuilder.setVisibility(Integer.parseInt(extras.getString("vis"))); } catch (NumberFormatException nfe) { } } else if (extrasRoot.containsKey("visibility")) { try { mBuilder.setVisibility(Integer.parseInt(extrasRoot.getString("visibility"))); } catch (NumberFormatException nfe) { } } else if (extrasRoot.containsKey("vis")) { try { mBuilder.setVisibility(Integer.parseInt(extrasRoot.getString("vis"))); } catch (NumberFormatException nfe) { } } //Icon background color int accent_argb = 0xFFFFFFFF; if (extras.containsKey("accentARGB")) { try { accent_argb = TiColorHelper.parseColor(extras.getString("accentARGB")); mBuilder.setColor(accent_argb); } catch (Exception ex) { try { accent_argb = Integer.parseInt(extras.getString("accentARGB")); mBuilder.setColor(accent_argb); } catch (NumberFormatException nfe) { } } } else if (extras.containsKey("bgac")) { try { accent_argb = TiColorHelper.parseColor(extras.getString("bgac")); mBuilder.setColor(accent_argb); } catch (Exception ex) { try { accent_argb = Integer.parseInt(extras.getString("bgac")); mBuilder.setColor(accent_argb); } catch (NumberFormatException nfe) { } } } else if (extrasRoot.containsKey("accentARGB")) { try { accent_argb = TiColorHelper.parseColor(extrasRoot.getString("accentARGB")); mBuilder.setColor(accent_argb); } catch (Exception ex) { try { accent_argb = Integer.parseInt(extrasRoot.getString("accentARGB")); mBuilder.setColor(accent_argb); } catch (NumberFormatException nfe) { } } } else if (extrasRoot.containsKey("bgac")) { try { accent_argb = TiColorHelper.parseColor(extrasRoot.getString("bgac")); mBuilder.setColor(accent_argb); } catch (Exception ex) { try { accent_argb = Integer.parseInt(extrasRoot.getString("bgac")); mBuilder.setColor(accent_argb); } catch (NumberFormatException nfe) { } } } NotificationManager nm = (NotificationManager) appContext .getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(notificationId, mBuilder.build()); } }
From source file:com.f8full.casserolesencours.CasserolesEnCoursActivity.java
/** * On service click.//from w ww . j a v a2 s .c o m * * @param view the view */ public void onServiceClick(View view) { boolean isChecked = ((ToggleButton) view).isChecked(); if (isChecked) { //turn on mAlohar.startServices(); //StatusView.setText("Service is running!"); ((TextView) findViewById(R.id.geolocationServiceStatus)) .setText(getString(R.string.geolocationStatusOn)); ((TextView) findViewById(R.id.geolocationServiceStatus)) .setTextColor(getResources().getColor(R.color.text_red)); ((TextView) findViewById(R.id.distanceFilterNA)).setVisibility(View.INVISIBLE); findViewById(R.id.FrequencyGroupLayout).setVisibility(View.VISIBLE); mDistanceFilterSpinner.setEnabled(true); //String freq = ((RadioButton)findViewById( ((RadioGroup)findViewById(R.id.pollFrequencyRadioGroup)).getCheckedRadioButtonId() )).getText().toString(); String text = getString(R.string.geolocationStatusOnNotification);//String.format(getString(R.string.geolocationOnNotification), freq); int icon = R.drawable.ic_launcher; CharSequence tickerText = text; long when = System.currentTimeMillis(); mNotification = new Notification(icon, tickerText, when); mNotification.flags |= Notification.FLAG_ONGOING_EVENT; CharSequence contentText = getString(R.string.geolocationOnNotificationNoFreq); CharSequence contentTitle = getString(R.string.app_name); Intent notificationIntent = new Intent(this, CasserolesEnCoursActivity.class); mNotification.contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); mNotification.setLatestEventInfo(this, contentTitle, contentText, mNotification.contentIntent); mNotificationManager.notify(R.layout.main, mNotification); } else { //turn off mAlohar.stopServices(); ((TextView) findViewById(R.id.geolocationServiceStatus)) .setText(getString(R.string.geolocationStatusOff)); ((TextView) findViewById(R.id.geolocationServiceStatus)) .setTextColor(getResources().getColor(R.color.text_green)); ((TextView) findViewById(R.id.distanceFilterNA)).setVisibility(View.VISIBLE); findViewById(R.id.FrequencyGroupLayout).setVisibility(View.INVISIBLE); mDistanceFilterSpinner.setSelection(0); mDistanceFilterSpinner.setEnabled(false); //((RadioGroup) findViewById(R.id.pollFrequencyRadioGroup)).check(-1); cancelActiveTasks(); mLocationPollThreadExecutor.purge(); //That is a hack, some code path must be missed, I'm tracking a thread leak bug when app is in background for a long time mLocationPollThreadExecutor.shutdown(); mLocationPollThreadExecutor = new ScheduledThreadPoolExecutor(20); mIsStationary = true; mNotificationManager.cancel(R.layout.main); } }
From source file:github.daneren2005.dsub.util.Util.java
public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song) { // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(), System.currentTimeMillis()); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; boolean playing = downloadService.getPlayerState() == PlayerState.STARTED; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); setupViews(expandedContentView, context, song, playing); notification.bigContentView = expandedContentView; }/*from w w w .j a v a2 s .c o m*/ RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification); setupViews(smallContentView, context, song, playing); notification.contentView = smallContentView; Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); handler.post(new Runnable() { @Override public void run() { downloadService.startForeground(Constants.NOTIFICATION_ID_PLAYING, notification); } }); // Update widget DSubWidgetProvider.notifyInstances(context, downloadService, true); }
From source file:org.wso2.iot.agent.services.operation.OperationManager.java
/** * Lock the device.// w w w .jav a 2 s. c o m * * @param operation - Operation object. */ public void lockDevice(org.wso2.iot.agent.beans.Operation operation) throws AndroidAgentException { operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); JSONObject inputData; String message = null; boolean isHardLockEnabled = false; try { if (operation.getPayLoad() != null) { inputData = new JSONObject(operation.getPayLoad().toString()); message = inputData.getString(Constants.ADMIN_MESSAGE); isHardLockEnabled = inputData.getBoolean(Constants.IS_HARD_LOCK_ENABLED); } } catch (JSONException e) { operation.setStatus(resources.getString(R.string.operation_value_error)); operation.setOperationResponse("Error in parsing LOCK payload."); resultBuilder.build(operation); throw new AndroidAgentException("Invalid JSON format.", e); } if (isHardLockEnabled && Constants.SYSTEM_APP_ENABLED) { if (message == null || message.isEmpty()) { message = resources.getString(R.string.txt_lock_activity); } Preference.putBoolean(context, Constants.IS_LOCKED, true); Preference.putString(context, Constants.LOCK_MESSAGE, message); operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); enableHardLock(message, operation); } else { operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(context.getString(R.string.alert_message)) .setContentText(message).setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0)); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, mBuilder.build()); devicePolicyManager.lockNow(); } if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Device locked"); } }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void notifySecondDMs(Context context, int secondAccount) { DMDataSource data = DMDataSource.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int numberNew = sharedPrefs.getInt("dm_unread_" + secondAccount, 0); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;/*ww w .j a v a 2 s. c o m*/ Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); String name; String message; String messageLong; NotificationCompat.InboxStyle inbox = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; messageLong = "<b>@" + name + "</b>: " + data.getNewestMessage(secondAccount); largeIcon = getImage(context, name); } else { // more than one dm message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); inbox = getDMInboxStyle(numberNew, secondAccount, context, message); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setAutoCancel(true) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { mBuilder.setStyle(inbox); } 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); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, 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); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:de.ub0r.android.websms.connector.common.Utils.java
/** * Show update notification.//from w w w .j a va 2s.c o m * * @param context * {@link Context} * @param pkg * package */ public static void showUpdateNotification(final Context context, final String pkg) { Notification n = new Notification(android.R.drawable.stat_sys_warning, context.getString(R.string.update_title), 0); n.flags = Notification.FLAG_AUTO_CANCEL; PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkg)), PendingIntent.FLAG_UPDATE_CURRENT); n.setLatestEventInfo(context, context.getString(R.string.update_title), context.getString(R.string.update_message), pi); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(0, n); }
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
@Override public void onKey(int primaryCode, int[] keyCodes) { final InputConnection ic = getCurrentInputConnection(); playClick();/*from ww w . ja v a 2s. co m*/ printChar = true; if (primaryCode != 126 && primaryCode != -5 && primaryCode != -1 && primaryCode != EmojiKeyboardView.KEYCODE_EMOJI_1 && primaryCode != EmojiKeyboardView.KEYCODE_EMOJI_2 && primaryCode != EmojiKeyboardView.KEYCODE_EMOJI_3 && primaryCode != EmojiKeyboardView.KEYCODE_EMOJI_4 && primaryCode != EmojiKeyboardView.KEYCODE_EMOJI_5) { keyPressCounter++; if (keyPressCounter > 100 && keyPressCounter <= 1000 && keypresscounter1.equals("false")) { NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard", System.currentTimeMillis()); PendingIntent pending = PendingIntent.getActivity(this, 0, new Intent(this, Home.class), 0); notify.setLatestEventInfo(getApplicationContext(), "Warming up!", "Type more than 100 characters", pending); notif.notify(0, notify); Preferences.setDefaults("keypresscounter1", "true", getApplicationContext()); } else if (keyPressCounter > 10000 && keyPressCounter <= 10000 && keypresscounter2.equals("false")) { NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard", System.currentTimeMillis()); PendingIntent pending = PendingIntent.getActivity(this, 0, new Intent(this, Home.class), 0); notify.setLatestEventInfo(getApplicationContext(), "Keep it up!", "Type more than 1000 characters", pending); notif.notify(0, notify); Preferences.setDefaults("keypresscounter2", "true", getApplicationContext()); } else if (keyPressCounter > 10000 && keypresscounter3.equals("false")) { NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard", System.currentTimeMillis()); PendingIntent pending = PendingIntent.getActivity(this, 0, new Intent(this, Home.class), 0); notify.setLatestEventInfo(getApplicationContext(), "Typing master!", "Type more than 10000 characters", pending); notif.notify(0, notify); Preferences.setDefaults("keypresscounter3", "true", getApplicationContext()); } Preferences.setDefaults("keypresses", String.valueOf(keyPressCounter), getApplicationContext()); } switch (primaryCode) { case 58: ic.commitText(":", 1); if (autoSpacing) { ic.commitText(" ", 1); } break; case 59: ic.commitText(";", 1); if (autoSpacing) { ic.commitText(" ", 1); } break; case 33: ic.commitText("!", 1); if (autoSpacing) { ic.commitText(" ", 1); } if (autoCapitalize) { caps = true; keyboard.setShifted(caps); kv.invalidateAllKeys(); printChar = false; } break; case 63: ic.commitText("?", 1); if (autoSpacing) { ic.commitText(" ", 1); } if (autoCapitalize) { caps = true; keyboard.setShifted(caps); kv.invalidateAllKeys(); printChar = false; } break; case -5: if (lang.equals("seclang")) { if (orient.equals("portrait")) { keyboard = prilang; } else if (orient.equals("landscape")) { keyboard = prilang_landscape; } kv.setKeyboard(keyboard); kv.invalidateAllKeys(); lang = "prilang"; } else if (lang.equals("prilang")) { if (orient.equals("portrait")) { keyboard = seclang; } else if (orient.equals("landscape")) { keyboard = seclang_landscape; } kv.setKeyboard(keyboard); kv.invalidateAllKeys(); lang = "seclang"; } break; case 32: ic.commitText(" ", 1); if (autoCapitalize) { if (String.valueOf(ic.getTextBeforeCursor(2, 0)).equals(". ")) { caps = true; keyboard.setShifted(caps); kv.invalidateAllKeys(); printChar = false; } } break; case 126: ic.deleteSurroundingText(1, 0); if (autoCapitalize) { if (String.valueOf(ic.getTextBeforeCursor(1, 0)).equals(".") || String.valueOf(ic.getTextBeforeCursor(2, 0)).equals(". ") || String.valueOf(ic.getTextBeforeCursor(2, 0)).equals("")) { caps = true; keyboard.setShifted(caps); kv.invalidateAllKeys(); printChar = false; } } break; case 44: ic.commitText(",", 1); if (autoSpacing) { ic.commitText(" ", 1); } break; case 46: ic.commitText(".", 1); if (autoSpacing) { ic.commitText(" ", 1); } if (autoCapitalize) { caps = true; keyboard.setShifted(caps); kv.invalidateAllKeys(); printChar = false; } break; case -1: ic.performEditorAction(EditorInfo.IME_ACTION_GO); break; case EmojiKeyboardView.KEYCODE_EMOJI_1: keyboard = new Keyboard(this, R.xml.emoji_a1); kv.setKeyboard(keyboard); kv.invalidateAllKeys(); emoji = 1; eScreen = 1; break; case EmojiKeyboardView.KEYCODE_EMOJI_2: keyboard = new Keyboard(this, R.xml.emoji_b1); kv.setKeyboard(keyboard); kv.invalidateAllKeys(); emoji = 2; eScreen = 1; break; case EmojiKeyboardView.KEYCODE_EMOJI_3: keyboard = new Keyboard(this, R.xml.emoji_c1); kv.setKeyboard(keyboard); kv.invalidateAllKeys(); emoji = 3; eScreen = 1; break; case EmojiKeyboardView.KEYCODE_EMOJI_4: keyboard = new Keyboard(this, R.xml.emoji_d1); kv.setKeyboard(keyboard); kv.invalidateAllKeys(); emoji = 4; eScreen = 1; break; case EmojiKeyboardView.KEYCODE_EMOJI_5: keyboard = new Keyboard(this, R.xml.emoji_e1); kv.setKeyboard(keyboard); kv.invalidateAllKeys(); emoji = 5; eScreen = 1; break; default: char code = (char) primaryCode; if (allCaps) { if (Character.isLetter(code) && capsLock) { code = Character.toLowerCase(code); } else if (Character.isLetter(code) && !capsLock) { code = Character.toUpperCase(code); } } else { if (Character.isLetter(code) && caps) { code = Character.toUpperCase(code); } } String character = String.valueOf(code); ic.commitText(character, 1); } if (printedDifferent) { ic.deleteSurroundingText(1, 0); } if (printedDot) { ic.deleteSurroundingText(1, 0); if (autoCapitalize) { caps = true; keyboard.setShifted(caps); kv.invalidateAllKeys(); printChar = false; } } if (doubleUp == 2) { capsChange(); } else { changeCaps(); } }
From source file:com.dwdesign.tweetings.service.TweetingsService.java
private Notification buildNotification(final String title, final String message, final int icon, final Intent content_intent, final Intent delete_intent) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setTicker(message);/*from w w w . j a v a 2s . c o m*/ builder.setContentTitle(title); builder.setContentText(message); builder.setAutoCancel(true); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(icon); if (delete_intent != null) { builder.setDeleteIntent( PendingIntent.getBroadcast(this, 0, delete_intent, PendingIntent.FLAG_UPDATE_CURRENT)); } if (content_intent != null) { builder.setContentIntent( PendingIntent.getActivity(this, 0, content_intent, PendingIntent.FLAG_UPDATE_CURRENT)); } int defaults = 0; final Calendar now = Calendar.getInstance(); if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_SOUND, true) && !mPreferences.getBoolean("silent_notifications_at_" + now.get(Calendar.HOUR_OF_DAY), false)) { Uri soundUri = Uri.parse(mPreferences.getString(PREFERENCE_KEY_NOTIFICATION_RINGTONE, "android.resource://" + getPackageName() + "/" + R.raw.notify)); builder.setSound(soundUri, Notification.STREAM_DEFAULT); } if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_VIBRATION, true) && !mPreferences.getBoolean("silent_notifications_at_" + now.get(Calendar.HOUR_OF_DAY), false)) { defaults |= Notification.DEFAULT_VIBRATE; } if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_LIGHTS, true) && !mPreferences.getBoolean("silent_notifications_at_" + now.get(Calendar.HOUR_OF_DAY), false)) { final int color_def = getResources().getColor(R.color.holo_blue_dark); final int color = mPreferences.getInt(PREFERENCE_KEY_NOTIFICATION_LIGHT_COLOR, color_def); builder.setLights(color, 1000, 2000); } builder.setDefaults(defaults); return builder.getNotification(); }