List of usage examples for android.app PendingIntent FLAG_CANCEL_CURRENT
int FLAG_CANCEL_CURRENT
To view the source code for android.app PendingIntent FLAG_CANCEL_CURRENT.
Click Source Link
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:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java
private void showUpdateNotification() { Log.d(TAG, "showUpdateNotification: " + getKeyboardString()); // Intent for triggering the update confirmation page. Intent updateConfirmation = new Intent(this, UpdateConfirmationActivity.class); updateConfirmation.putExtra(EXTRA_KEYBOARD_NAME, mKeyboardName); updateConfirmation.putExtra(EXTRA_KEYBOARD_ADDRESS, mKeyboardAddress); updateConfirmation.putExtra(EXTRA_KEYBOARD_FIRMWARE_VERSION, mKeyboardFirmwareVersion); updateConfirmation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Intent for postponing update. Intent postponeUpdate = new Intent(ACTION_KEYBOARD_UPDATE_POSTPONED); // Wrap intents into pending intents for notification use. PendingIntent laterIntent = PendingIntent.getBroadcast(this, 0, postponeUpdate, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent installIntent = PendingIntent.getActivity(this, 0, updateConfirmation, PendingIntent.FLAG_CANCEL_CURRENT); // Create a notification object with two buttons (actions) mUpdateNotification = new NotificationCompat.Builder(this).setCategory(Notification.CATEGORY_SYSTEM) .setContentTitle(getString(R.string.notification_update_title)) .setContentText(getString(R.string.notification_update_text)).setSmallIcon(R.drawable.ic_keyboard) .addAction(new NotificationCompat.Action.Builder(R.drawable.ic_later, getString(R.string.notification_update_later), laterIntent).build()) .addAction(new NotificationCompat.Action.Builder(R.drawable.ic_install, getString(R.string.notification_update_install), installIntent).build()) .setAutoCancel(true).setOnlyAlertOnce(true).build(); // Show the notification via notification manager NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(UPDATE_NOTIFICATION_ID, mUpdateNotification); }
From source file:br.com.arlsoft.pushclient.PushClientModule.java
public static void sendNotification(Bundle extras) { if (extras == null || extras.isEmpty()) return;/*from w w w . jav a 2 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:org.wso2.cdm.agent.AuthenticationActivity.java
private void startLocalNotification(Float interval) { long firstTime = SystemClock.elapsedRealtime(); firstTime += 1 * 1000;/*from w w w.ja va2 s .co m*/ Intent downloader = new Intent(context, AlarmReceiver.class); PendingIntent recurringDownload = PendingIntent.getBroadcast(context, 0, downloader, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Float seconds = interval; if (interval < 1.0) { alarms.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, seconds.intValue(), recurringDownload); } else { alarms.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, seconds.intValue(), recurringDownload); } }
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private void setSamplingAlarm(String action, long timeOut, int extra) { Log.v(TAG, "LocTrigService: Setting alarm: " + action); cancelSamplingAlarm(action);/*from w w w. j av a 2 s. c o m*/ Intent i = new Intent(action); i.setPackage(getPackageName()); i.putExtra(KEY_SAMPLING_ALARM_EXTRA, extra); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE); alarmMan.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + timeOut, pi); }
From source file:org.ohmage.triggers.types.location.LocTrigService.java
private void setSamplingAlarm(String action, long timeOut, int extra) { Log.i(DEBUG_TAG, "LocTrigService: Setting alarm: " + action); cancelSamplingAlarm(action);/* w w w . j ava 2s . c om*/ Intent i = new Intent(action); i.putExtra(KEY_SAMPLING_ALARM_EXTRA, extra); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE); alarmMan.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + timeOut, pi); }
From source file:com.mobilyzer.MeasurementScheduler.java
/** Set the interval for checkin in seconds */ public synchronized long setCheckinInterval(boolean isForced, long interval) { Logger.d("Scheduler->setCheckinInterval called " + interval); long min = Config.MIN_CHECKIN_INTERVAL_SEC; long max = Config.MAX_CHECKIN_INTERVAL_SEC; if (!isForced && this.checkinIntervalSec != -1) { min = this.batteryThreshold; }/*from w w w. j av a 2 s . c o m*/ // Check whether out of boundary and same with old value if (interval >= min && interval <= max && interval != this.checkinIntervalSec) { this.checkinIntervalSec = interval; Logger.i("Setting checkin interval to " + this.checkinIntervalSec + " seconds"); persistParams(Config.PREF_KEY_CHECKIN_INTERVAL, String.valueOf(this.checkinIntervalSec)); // the new checkin schedule will start // in PAUSE_BETWEEN_CHECKIN_CHANGE_MSEC seconds checkinIntentSender = PendingIntent.getBroadcast(this, 0, new UpdateIntent(UpdateIntent.CHECKIN_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + Config.PAUSE_BETWEEN_CHECKIN_CHANGE_MSEC, checkinIntervalSec * 1000, checkinIntentSender); } return this.checkinIntervalSec; }
From source file:org.broeuschmeul.android.gps.usb.provider.driver.USBGpsManager.java
/** * @param callingService/*from www .j a va 2 s .co m*/ * @param vendorId * @param productId * @param maxRetries */ public USBGpsManager(Service callingService, int vendorId, int productId, int maxRetries) { this.gpsVendorId = vendorId; this.gpsProductId = productId; this.callingService = callingService; this.maxConnectionRetries = maxRetries + 1; this.nbRetriesRemaining = maxConnectionRetries; this.appContext = callingService.getApplicationContext(); this.parser = new NmeaParser(10f, this.appContext); locationManager = (LocationManager) callingService.getSystemService(Context.LOCATION_SERVICE); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(callingService); deviceSpeed = sharedPreferences.getString(USBGpsProviderService.PREF_GPS_DEVICE_SPEED, callingService.getString(R.string.defaultGpsDeviceSpeed)); shouldSetTime = sharedPreferences.getBoolean(USBGpsProviderService.PREF_SET_TIME, false); timeSetAlready = true; defaultDeviceSpeed = callingService.getString(R.string.defaultGpsDeviceSpeed); setDeviceSpeed = !deviceSpeed.equals(callingService.getString(R.string.autoGpsDeviceSpeed)); sirfGps = sharedPreferences.getBoolean(USBGpsProviderService.PREF_SIRF_GPS, false); notificationManager = (NotificationManager) callingService.getSystemService(Context.NOTIFICATION_SERVICE); parser.setLocationManager(locationManager); Intent stopIntent = new Intent(USBGpsProviderService.ACTION_STOP_GPS_PROVIDER); PendingIntent stopPendingIntent = PendingIntent.getService(appContext, 0, stopIntent, PendingIntent.FLAG_CANCEL_CURRENT); connectionProblemNotificationBuilder = new NotificationCompat.Builder(appContext) .setContentIntent(stopPendingIntent).setSmallIcon(R.drawable.ic_stat_notify); Intent restartIntent = new Intent(USBGpsProviderService.ACTION_START_GPS_PROVIDER); PendingIntent restartPendingIntent = PendingIntent.getService(appContext, 0, restartIntent, PendingIntent.FLAG_CANCEL_CURRENT); serviceStoppedNotificationBuilder = new NotificationCompat.Builder(appContext) .setContentIntent(restartPendingIntent).setSmallIcon(R.drawable.ic_stat_notify) .setContentTitle( appContext.getString(R.string.service_closed_because_connection_problem_notification_title)) .setContentText( appContext.getString(R.string.service_closed_because_connection_problem_notification)); usbManager = (UsbManager) callingService.getSystemService(Service.USB_SERVICE); }
From source file:com.safecell.HomeScreenActivity.java
public void showNotification(String msg) { if (!new ConfigurePreferences(contextHomeScreenActivity).getTripStrated()) { Notification notification = new Notification(R.drawable.launch_icon, "Notify", System.currentTimeMillis()); notification.setLatestEventInfo(HomeScreenActivity.this, "SafeCell", msg, PendingIntent.getActivity( HomeScreenActivity.this.getBaseContext(), 0, null, PendingIntent.FLAG_CANCEL_CURRENT)); mManager.notify(APP_ID, notification); }// w w w . j a va 2 s.c o m }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * Adds actions to a push notification. This is called by the Push broadcast receiver probably before * Codename One is initialized// w w w . j a v a2s .com * @param provider Reference to the app's main class which implements PushActionsProvider * @param categoryId The category ID of the push notification. * @param builder The builder for the push notification. * @param targetIntent The target intent... this should go to the app's main Activity. * @param context The current context (inside the Broadcast receiver). * @throws IOException */ public static void addActionsToNotification(PushActionsProvider provider, String categoryId, NotificationCompat.Builder builder, Intent targetIntent, Context context) throws IOException { // NOTE: THis will likely run when the main activity isn't running so we won't have // access to any display properties... just native Android APIs will be accessible. PushActionCategory category = null; PushActionCategory[] categories; if (provider != null) { categories = provider.getPushActionCategories(); } else { categories = getInstalledPushActionCategories(context); } for (PushActionCategory candidateCategory : categories) { if (categoryId.equals(candidateCategory.getId())) { category = candidateCategory; break; } } if (category == null) { return; } int requestCode = 1; for (PushAction action : category.getActions()) { Intent newIntent = (Intent) targetIntent.clone(); newIntent.putExtra("pushActionId", action.getId()); PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode++, newIntent, PendingIntent.FLAG_CANCEL_CURRENT); try { int iconId = 0; try { iconId = Integer.parseInt(action.getIcon()); } catch (Exception ex) { } //android.app.Notification.Action.Builder actionBuilder = new android.app.Notification.Action.Builder(iconId, action.getTitle(), contentIntent); System.out .println("Adding action " + action.getId() + ", " + action.getTitle() + ", icon=" + iconId); if (ActionWrapper.BuilderWrapper.isSupported()) { // We need to take this abstracted "wrapper" approach because the Action.Builder class, and RemoteInput class // aren't available until API 22. // These classes use reflection to provide support for these classes safely. ActionWrapper.BuilderWrapper actionBuilder = new ActionWrapper.BuilderWrapper(iconId, action.getTitle(), contentIntent); if (action.getTextInputPlaceholder() != null && RemoteInputWrapper.isSupported()) { RemoteInputWrapper.BuilderWrapper remoteInputBuilder = new RemoteInputWrapper.BuilderWrapper( action.getId() + "$Result"); remoteInputBuilder.setLabel(action.getTextInputPlaceholder()); RemoteInputWrapper remoteInput = remoteInputBuilder.build(); actionBuilder.addRemoteInput(remoteInput); } ActionWrapper actionWrapper = actionBuilder.build(); new NotificationCompatWrapper.BuilderWrapper(builder).addAction(actionWrapper); } else { builder.addAction(iconId, action.getTitle(), contentIntent); } } catch (Exception ex) { ex.printStackTrace(); } } }