List of usage examples for android.content Context NOTIFICATION_SERVICE
String NOTIFICATION_SERVICE
To view the source code for android.content Context NOTIFICATION_SERVICE.
Click Source Link
From source file:eu.codeplumbers.cosi.services.CosiContactService.java
public void showNotification() { mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this); mBuilder.setContentTitle(getString(R.string.lbl_contacts)) .setContentText(getString(R.string.lbl_notes_ongoing_sync)) .setSmallIcon(R.drawable.ic_call_black_24dp).setOngoing(true); }
From source file:com.ntsync.android.sync.syncadapter.SyncAdapter.java
private void notifyUserConctactNotSynced(int maxCount, int totalLocalContacts, String accountName) { AccountManager acm = AccountManager.get(mContext); Account account = new Account(accountName, Constants.ACCOUNT_TYPE); String lastTimeShown = acm.getUserData(account, NOTIF_SHOWN_CONTACTS_SYNCED); Long lastTime;//from w ww. ja v a 2 s. c o m try { lastTime = lastTimeShown != null ? Long.parseLong(lastTimeShown) : null; } catch (NumberFormatException ex) { LogHelper.logWCause(TAG, "Invalid Config-Settings:" + NOTIF_SHOWN_CONTACTS_SYNCED + " Value:" + lastTimeShown, ex); lastTime = null; } if (lastTime == null || System.currentTimeMillis() > lastTime.longValue() + NOTIF_WAIT_TIME) { // Create Shop-Intent Intent shopIntent = new Intent(mContext, ShopActivity.class); shopIntent.putExtra(ShopActivity.PARM_ACCOUNT_NAME, account.name); // Adds the back stack TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); stackBuilder.addParentStack(ShopActivity.class); stackBuilder.addNextIntent(shopIntent); // Create Notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(Constants.NOTIF_ICON) .setContentTitle(String.format(getText(R.string.notif_contactnotsynced_title), maxCount, totalLocalContacts)) .setContentText(String.format(getText(R.string.notif_contactnotsynced_content), account.name)) .setAutoCancel(true).setOnlyAlertOnce(true) .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(Constants.NOTIF_CONTACTS_NOT_SYNCED, mBuilder.build()); acm.setUserData(account, NOTIF_SHOWN_CONTACTS_SYNCED, String.valueOf(System.currentTimeMillis())); } }
From source file:org.wso2.iot.agent.services.operation.OperationManager.java
/** * Lock the device./*from ww w . ja va 2s . co 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:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
@Override public void onKey(int primaryCode, int[] keyCodes) { final InputConnection ic = getCurrentInputConnection(); playClick();/*from w w w . jav a2s . c o 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:de.ub0r.android.websms.connector.common.Utils.java
/** * Show update notification./* ww w . j a v a 2 s . 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:org.wso2.emm.agent.services.operation.OperationManager.java
/** * Lock the device./*from w ww .j a v a 2 s . c o m*/ * * @param operation - Operation object. */ public void lockDevice(org.wso2.emm.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:br.com.arlsoft.pushclient.PushClientModule.java
public static void sendNotification(Bundle extras) { if (extras == null || extras.isEmpty()) return;/* w w w . j a v a2 s . c o 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.mozilla.SUTAgentAndroid.service.DoCommand.java
private void SendNotification(String tickerText, String expandedText) { NotificationManager notificationManager = (NotificationManager) contextWrapper .getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.ateamlogo; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.flags |= (Notification.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_LIGHTS; Context context = contextWrapper.getApplicationContext(); // Intent to launch an activity when the extended text is clicked Intent intent2 = new Intent(contextWrapper, SUTAgentAndroid.class); PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent2, 0); notification.setLatestEventInfo(context, tickerText, expandedText, launchIntent); notificationManager.notify(1959, notification); }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
private void CancelNotification() { NotificationManager notificationManager = (NotificationManager) contextWrapper .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(1959);//from www . j a v a 2s . com }