@Override protected void onHandleIntent(Intent intent) { if (builder == null) { cancellUpdate(); return; } long progress = Math.min(duration, System.currentTimeMillis() - start); Notification notification = builder.setProgress((int) duration, (int) progress, false).build(); if (progress == duration) { cancellUpdate(); } NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); notification.flags |= Notification.FLAG_NO_CLEAR; notificationManager.notify(TaskService.CURRENT_TASK_NOTIFICATION_ID, notification); }
public static void displayNotification(Context context, String text) { Intent openIntent = new Intent(context, MainActivity.class); Notification notification = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.icon) .setContentTitle(context.getResources().getString(R.string.notification_title)) .setContentText(text) .setContentIntent(PendingIntent.getActivity(context, 0, openIntent, 0)) .addAction( android.R.drawable.ic_menu_close_clear_cancel, context.getResources().getString(R.string.menu_exit), PendingIntent.getBroadcast(context, 0, new ExitIntent(), 0)) .addAction( android.R.drawable.ic_menu_manage, context.getResources().getString(R.string.menu_main_screen), PendingIntent.getActivity(context, 0, openIntent, 0)) .build(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); notification.flags |= Notification.FLAG_ONGOING_EVENT; notificationManager.notify(1983, notification); }
/** * Creates the notification object. * * @see #setNormalNotification * @see #setBigTextStyleNotification * @see #setBigPictureStyleNotification * @see #setInboxStyleNotification */ @Override protected Void doInBackground(Void... params) { Notification noti = new Notification(); switch (style) { case NORMAL: noti = setNormalNotification(); break; case BIG_TEXT_STYLE: noti = setBigTextStyleNotification(); break; case BIG_PICTURE_STYLE: noti = setBigPictureStyleNotification(); break; case INBOX_STYLE: noti = setInboxStyleNotification(); break; case CUSTOM_VIEW: noti = setCustomViewNotification(); break; } noti.defaults |= Notification.DEFAULT_LIGHTS; noti.defaults |= Notification.DEFAULT_VIBRATE; noti.defaults |= Notification.DEFAULT_SOUND; noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE; mNotificationManager.notify(0, noti); return null; }
public void onCreate() { int flags, screenLightVal = 1; Sensor mSensor; List<Sensor> sensors; if (scanData == null) return; // no ScanData, not possible to run correctly... PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); try { screenLightVal = Integer.parseInt(SP.getString("screenLight", "2")); } catch (NumberFormatException nfe) { } if (screenLightVal == 1) flags = PowerManager.PARTIAL_WAKE_LOCK; else if (screenLightVal == 3) flags = PowerManager.FULL_WAKE_LOCK; else flags = PowerManager.SCREEN_DIM_WAKE_LOCK; wl = pm.newWakeLock(flags, "OpenWLANMap"); wl.acquire(); while (myWLocate == null) { try { myWLocate = new MyWLocate(this); break; } catch (IllegalArgumentException iae) { myWLocate = null; } try { Thread.sleep(100); } catch (InterruptedException ie) { } } try { scanData.setUploadThres(Integer.parseInt(SP.getString("autoUpload", "0"))); } catch (NumberFormatException nfe) { } try { scanData.setNoGPSExitInterval( Integer.parseInt(SP.getString("noGPSExitInterval", "0")) * 60 * 1000); } catch (NumberFormatException nfe) { } Intent intent = new Intent(this, OWMapAtAndroid.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0); notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon) .setContentTitle(getResources().getText(R.string.app_name)) .setContentText("") .setContentIntent(pendIntent) .build(); notification.flags |= Notification.FLAG_NO_CLEAR; notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(1703, notification); getScanData().setService(this); getScanData().setmView(new HUDView(this)); getScanData().getmView().setValue(getScanData().incStoredValues()); WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); params.gravity = Gravity.LEFT | Gravity.BOTTOM; params.setTitle("Load Average"); WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); wm.addView(getScanData().getmView(), params); sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); sensorManager.registerListener( this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); sensorManager.registerListener( this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_GAME); sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); mSensor = sensors.get(0); getScanData().getTelemetryData().setAccelMax(mSensor.getMaximumRange()); telemetryDir = Environment.getExternalStorageDirectory().getPath() + "/telemetry/"; File dir = new File(telemetryDir); dir.mkdir(); connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); }
private void suppressLights(Notification notification) { notification.defaults &= (~Notification.DEFAULT_LIGHTS); notification.flags &= (~Notification.FLAG_SHOW_LIGHTS); }