Example usage for android.app Notification FLAG_ONGOING_EVENT

List of usage examples for android.app Notification FLAG_ONGOING_EVENT

Introduction

In this page you can find the example usage for android.app Notification FLAG_ONGOING_EVENT.

Prototype

int FLAG_ONGOING_EVENT

To view the source code for android.app Notification FLAG_ONGOING_EVENT.

Click Source Link

Document

Bit to be bitwise-ored into the #flags field that should be set if this notification is in reference to something that is ongoing, like a phone call.

Usage

From source file:com.wifi.brainbreaker.mydemo.spydroid.ui.SpydroidActivity.java

public void onStart() {
    super.onStart();

    // Lock screen
    mWakeLock.acquire();//from   www .j  a v a 2s  . co  m

    // Did the user disabled the notification ?
    if (mApplication.notificationEnabled) {
        Intent notificationIntent = new Intent(this, SpydroidActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        Notification notification = builder.setContentIntent(pendingIntent).setWhen(System.currentTimeMillis())
                .setTicker(getText(R.string.notification_title)).setSmallIcon(R.drawable.icon)
                .setContentTitle(getText(R.string.notification_title))
                .setContentText(getText(R.string.notification_content)).build();
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification);
    } else {
        removeNotification();
    }

    bindService(new Intent(this, CustomHttpServer.class), mHttpServiceConnection, Context.BIND_AUTO_CREATE);
    bindService(new Intent(this, CustomRtspServer.class), mRtspServiceConnection, Context.BIND_AUTO_CREATE);

}

From source file:com.alex.vmandroid.services.RecordDBService.java

@Override
public void onCreate() {
    super.onCreate();

    //region ????
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    Intent intent = new Intent(this, RecordDBActivity.class);
    //PendingIntent 
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    mBuilder.setSmallIcon(R.drawable.vm_android_app_icon).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.record)).setContentIntent(pendingIntent);
    Notification mNotification = mBuilder.build();

    //  ?  //from ww w . j a  v  a 2 s  .  c o m
    //mNotification.icon = R.drawable.icon_upload_location;
    //??
    mNotification.flags = Notification.FLAG_ONGOING_EVENT;//FLAG_ONGOING_EVENT ??  FLAG_AUTO_CANCEL  ??
    //???Light
    mNotification.defaults = Notification.DEFAULT_VIBRATE;
    //??
    mNotification.tickerText = "???";
    //?
    mNotification.when = System.currentTimeMillis();

    //  ?  
    //mNotification.icon = R.drawable.icon_upload_location;
    //??
    mNotification.flags = Notification.FLAG_ONGOING_EVENT;//FLAG_ONGOING_EVENT ??  FLAG_AUTO_CANCEL  ??
    //???Light
    mNotification.defaults = Notification.DEFAULT_VIBRATE;
    //??
    mNotification.tickerText = "???";
    //?
    mNotification.when = System.currentTimeMillis();
    //id??
    int notifyId = 1001;
    startForeground(notifyId, mNotification);
    //endregion

    //region ?
    mReceiver = new RecordDBReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(RecordDBService.RecordDBServiceAction);
    registerReceiver(mReceiver, intentFilter);
    mReceiver2 = new MessageReceiver();
    intentFilter = new IntentFilter();
    intentFilter.addAction(RecordDBReceiver.ACTION);
    registerReceiver(mReceiver2, intentFilter);
    //endregion

    //region ??
    mLocationClient = new AMapLocationClient(this);
    //???
    AMapLocationClientOption locationOption = new AMapLocationClientOption();
    //??
    mLocationClient.setLocationListener(this);
    //???Battery_Saving?Device_Sensors?
    locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
    //?,??,2000ms
    locationOption.setInterval(2000);
    //??
    mLocationClient.setLocationOption(locationOption);
    //endregion
}

From source file:org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.java

public void sendNotification(StatusBarNotification statusBarNotification, boolean requestAnswer) {

    Notification notification = statusBarNotification.getNotification();
    AppDatabase appDatabase = new AppDatabase(context);

    if ((notification.flags & Notification.FLAG_FOREGROUND_SERVICE) != 0
            || (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0
            || (notification.flags & Notification.FLAG_LOCAL_ONLY) != 0) {
        //This is not a notification we want!
        return;//from   w  ww. j av  a 2s.c  om
    }

    appDatabase.open();
    if (!appDatabase.isEnabled(statusBarNotification.getPackageName())) {
        return;
        // we dont want notification from this app
    }
    appDatabase.close();

    String key = getNotificationKeyCompat(statusBarNotification);
    String packageName = statusBarNotification.getPackageName();
    String appName = AppsHelper.appNameLookup(context, packageName);

    if ("com.facebook.orca".equals(packageName) && (statusBarNotification.getId() == 10012)
            && "Messenger".equals(appName) && notification.tickerText == null) {
        //HACK: Hide weird Facebook empty "Messenger" notification that is actually not shown in the phone
        return;
    }

    if (packageName.equals("com.google.android.googlequicksearchbox")) {
        //HACK: Hide Google Now notifications that keep constantly popping up (and without text because we don't know how to read them properly)
        return;
    }

    NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_NOTIFICATION);

    if (packageName.equals("org.kde.kdeconnect_tp")) {
        //Make our own notifications silent :)
        np.set("silent", true);
        np.set("requestAnswer", true); //For compatibility with old desktop versions of KDE Connect that don't support "silent"
    }
    /*
            if (sendIcons) {
    try {
        Drawable drawableAppIcon = AppsHelper.appIconLookup(context, packageName);
        Bitmap appIcon = ImagesHelper.drawableToBitmap(drawableAppIcon);
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        if (appIcon.getWidth() > 128) {
            appIcon = Bitmap.createScaledBitmap(appIcon, 96, 96, true);
        }
        appIcon.compress(Bitmap.CompressFormat.PNG, 90, outStream);
        byte[] bitmapData = outStream.toByteArray();
        np.setPayload(bitmapData);
    } catch (Exception e) {
        e.printStackTrace();
        Log.e("NotificationsPlugin", "Error retrieving icon");
    }
            }
    */
    np.set("id", key);
    np.set("appName", appName == null ? packageName : appName);
    np.set("isClearable", statusBarNotification.isClearable());
    np.set("ticker", getTickerText(notification));
    np.set("time", Long.toString(statusBarNotification.getPostTime()));
    if (requestAnswer) {
        np.set("requestAnswer", true);
        np.set("silent", true);
    }

    device.sendPackage(np);
}

From source file:com.online.fullsail.SaveWebMedia.java

@Override
protected void onPreExecute() {

    Intent intent = new Intent();
    final PendingIntent pendingIntent = PendingIntent.getActivity(this.context, 0, intent, 0);
    notification = new Notification(R.drawable.icon_notification, "Downloading...", System.currentTimeMillis());
    notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.contentView = new RemoteViews(this.context.getPackageName(), R.layout.download_notify);
    notification.contentIntent = pendingIntent;
    notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.icon);
    notification.contentView.setTextViewText(R.id.status_text, "Downloading Content...");
    notification.contentView.setProgressBar(R.id.status_progress, 100, 0, false);
    mNM.notify(timestamp, notification);
}

From source file:com.etime.ETimeActivity.java

/**
 * Notify the user with the message "message". Notification is set to
 * on-going, on-going is needed to tell android not to kill the app.
 * The phone with vibrate, and light up on notification. If the message
 * is the exact same message as the last message notified then the
 * notification is not set again.//from   w w w.j  a v  a2s .  c o  m
 * @param message  Message to notify user with
 */
protected void notify(String message) {
    if (message.equalsIgnoreCase(lastNotificationMessage)) {
        return;
    } else {
        lastNotificationMessage = message;
    }

    int icon = R.drawable.icon;
    long when = System.currentTimeMillis();
    Context context = getApplicationContext();
    CharSequence contentTitle = "ETime";
    Intent notificationIntent = new Intent(this, ETimeActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    notification.flags |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.setLatestEventInfo(context, contentTitle, message, contentIntent);

    mManager.notify("ETime", APP_ID, notification);
}

From source file:com.dattasmoon.pebble.plugin.NotificationService.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    // handle the prefs changing, because of how accessibility services
    // work, sharedprefsonchange listeners don't work
    if (watchFile.lastModified() > lastChange) {
        loadPrefs();/*  w  w w  .j av  a2  s.  c  om*/
    }
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "Service: Mode is: " + String.valueOf(mode.ordinal()));
    }
    // if we are off, don't do anything.
    if (mode == Mode.OFF) {
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Service: Mode is off, not sending any notifications");
        }
        return;
    }

    //handle quiet hours
    if (quiet_hours) {

        Calendar c = Calendar.getInstance();
        Date now = new Date(0, 0, 0, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE));
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Checking quiet hours. Now: " + now.toString() + " vs "
                    + quiet_hours_before.toString() + " and " + quiet_hours_after.toString());
        }

        if (quiet_hours_before.after(quiet_hours_after)) {
            if (now.after(quiet_hours_after) && now.before(quiet_hours_before)) {
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "Time is during quiet time. Returning.");
                }
                return;
            }

        } else if (now.before(quiet_hours_before) || now.after(quiet_hours_after)) {
            if (Constants.IS_LOGGABLE) {
                Log.i(Constants.LOG_TAG, "Time is before or after the quiet hours time. Returning.");
            }
            return;
        }

    }

    // handle if they only want notifications
    if (notifications_only) {
        if (event != null) {
            Parcelable parcelable = event.getParcelableData();
            if (!(parcelable instanceof Notification)) {

                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG,
                            "Event is not a notification and notifications only is enabled. Returning.");
                }
                return;
            }
        }
    }
    if (no_ongoing_notifs) {
        Parcelable parcelable = event.getParcelableData();
        if (parcelable instanceof Notification) {
            Notification notif = (Notification) parcelable;
            if ((notif.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) {
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG,
                            "Event is a notification, notification flag contains ongoing, and no ongoing notification is true. Returning.");
                }
                return;
            }
        } else {
            if (Constants.IS_LOGGABLE) {
                Log.i(Constants.LOG_TAG, "Event is not a notification.");
            }
        }
    }

    // Handle the do not disturb screen on settings
    PowerManager powMan = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
    if (Constants.IS_LOGGABLE) {
        Log.d(Constants.LOG_TAG, "NotificationService.onAccessibilityEvent: notifScreenOn=" + notifScreenOn
                + "  screen=" + powMan.isScreenOn());
    }
    if (!notifScreenOn && powMan.isScreenOn()) {
        return;
    }

    if (event == null) {
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Event is null. Returning.");
        }
        return;
    }
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "Event: " + event.toString());
    }

    // main logic
    PackageManager pm = getPackageManager();

    String eventPackageName;
    if (event.getPackageName() != null) {
        eventPackageName = event.getPackageName().toString();
    } else {
        eventPackageName = "";
    }
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "Service package list is: ");
        for (String strPackage : packages) {
            Log.i(Constants.LOG_TAG, strPackage);
        }
        Log.i(Constants.LOG_TAG, "End Service package list");
    }

    switch (mode) {
    case EXCLUDE:
        // exclude functionality
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Mode is set to exclude");
        }

        for (String packageName : packages) {
            if (packageName.equalsIgnoreCase(eventPackageName)) {
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, packageName + " == " + eventPackageName
                            + " which is on the exclude list. Returning.");
                }
                return;
            }
        }
        break;
    case INCLUDE:
        // include only functionality
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Mode is set to include only");
        }
        boolean found = false;
        for (String packageName : packages) {
            if (packageName.equalsIgnoreCase(eventPackageName)) {
                found = true;
                break;
            }
        }
        if (!found) {
            Log.i(Constants.LOG_TAG, eventPackageName + " was not found in the include list. Returning.");
            return;
        }
        break;
    }

    // get the title
    String title = "";
    try {
        boolean renamed = false;
        for (int i = 0; i < pkg_renames.length(); i++) {
            if (pkg_renames.getJSONObject(i).getString("pkg").equalsIgnoreCase(eventPackageName)) {
                renamed = true;
                title = pkg_renames.getJSONObject(i).getString("to");
            }
        }
        if (!renamed) {
            title = pm.getApplicationLabel(pm.getApplicationInfo(eventPackageName, 0)).toString();
        }
    } catch (NameNotFoundException e) {
        title = eventPackageName;
    } catch (JSONException e) {
        title = eventPackageName;
    }

    // get the notification text
    String notificationText = event.getText().toString();
    // strip the first and last characters which are [ and ]
    notificationText = notificationText.substring(1, notificationText.length() - 1);

    if (notification_extras) {
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Fetching extras from notification");
        }
        Parcelable parcelable = event.getParcelableData();
        if (parcelable instanceof Notification) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                notificationText += "\n" + getExtraBigData((Notification) parcelable, notificationText.trim());
            } else {
                notificationText += "\n" + getExtraData((Notification) parcelable, notificationText.trim());
            }

        }
    }

    // Check ignore lists
    for (int i = 0; i < ignores.length(); i++) {
        try {
            JSONObject ignore = ignores.getJSONObject(i);
            String app = ignore.getString("app");
            boolean exclude = ignore.optBoolean("exclude", true);
            boolean case_insensitive = ignore.optBoolean("insensitive", true);
            if ((!app.equals("-1")) && (!eventPackageName.equalsIgnoreCase(app))) {
                //this rule doesn't apply to all apps and this isn't the app we're looking for.
                continue;
            }
            String regex = "";
            if (case_insensitive) {
                regex += "(?i)";
            }
            if (!ignore.getBoolean("raw")) {
                regex += Pattern.quote(ignore.getString("match"));
            } else {
                regex += ignore.getString("match");
            }
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(notificationText);
            if (m.find()) {
                if (exclude) {
                    if (Constants.IS_LOGGABLE) {
                        Log.i(Constants.LOG_TAG, "Notification text of '" + notificationText + "' matches: '"
                                + regex + "' and exclude is on. Returning");
                    }
                    return;
                }
            } else {
                if (!exclude) {
                    if (Constants.IS_LOGGABLE) {
                        Log.i(Constants.LOG_TAG, "Notification text of '" + notificationText
                                + "' does not match: '" + regex + "' and include is on. Returning");
                    }
                    return;
                }

            }
        } catch (JSONException e) {
            continue;
        }
    }

    // Send the alert to Pebble

    sendToPebble(title, notificationText);

    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, event.toString());
        Log.i(Constants.LOG_TAG, event.getPackageName().toString());
    }
}

From source file:com.achep.acdisplay.notifications.OpenNotification.java

/**
 * Convenience method to check the notification's flags for
 * either {@link Notification#FLAG_ONGOING_EVENT} or
 * {@link Notification#FLAG_NO_CLEAR}./*from ww w .j  a v  a 2 s  . co  m*/
 */
public boolean isClearable() {
    return ((mNotification.flags & Notification.FLAG_ONGOING_EVENT) == 0)
            && ((mNotification.flags & Notification.FLAG_NO_CLEAR) == 0);
}

From source file:cm.aptoide.pt.DownloadQueueService.java

private void setNotification(int apkidHash, int progress) {

    String apkid = notifications.get(apkidHash).get("apkid");
    int size = Integer.parseInt(notifications.get(apkidHash).get("intSize"));
    String version = notifications.get(apkidHash).get("version");

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification);
    contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification);
    contentView.setTextViewText(R.id.download_notification_name,
            getString(R.string.download_alrt) + " " + apkid + " v." + version);
    contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, progress,
            false);/*w w w.jav  a2 s .  c  om*/

    Intent onClick = new Intent();
    onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt");
    onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    onClick.setAction("cm.aptoide.pt.FROM_NOTIFICATION");

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0);

    Notification notification = new Notification(R.drawable.ic_notification,
            getString(R.string.download_alrt) + " " + apkid, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = contentView;

    // Set the info for the notification panel.
    notification.contentIntent = onClickAction;
    //       notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Send the notification.
    // We use the position because it is a unique number.  We use it later to cancel.
    notificationManager.notify(apkidHash, notification);

    //      Log.d("Aptoide-DownloadQueueService", "Notification Set");
}

From source file:com.putlocker.upload.DownloadService.java

/**
 * @param job The job to notify about//from   ww  w. ja v a2 s  .  c  o m
 * @param context The context to use
 * Show a notification while this service is running.
 */
public Notification createDownloadNotification(PutlockerUpDownloadJob job, Context context, int progress) {
    CharSequence text;
    if (job.getJobType() == PutlockerUpDownloadJob.DOWNLOAD_JOB) {
        text = context.getText(R.string.remote_service_started);
    } else {
        text = context.getText(R.string.service_upload_started);
    }

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, PutlockerTransferList.class), 0);
    // Set the icon, scrolling text and timestamp
    Notification notification = new Notification(R.drawable.ic_launcher, text, System.currentTimeMillis());
    notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = new RemoteViews(context.getApplicationContext().getPackageName(),
            R.layout.download_progress);

    notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ic_launcher);

    if (job.getJobType() == PutlockerUpDownloadJob.DOWNLOAD_JOB) {

        if (FileFactory.typeFromFileName(job.getName()) == FileType.FILE_TYPE_VIDEO) {
            notification.contentIntent = PendingIntent.getActivity(this, 0,
                    getIntentForJob((PutlockerDownloadJob) job), Intent.FLAG_ACTIVITY_NEW_TASK);
        } else {
            notification.contentIntent = contentIntent;
        }

        notification.contentView.setTextViewText(R.id.status_text,
                context.getString(R.string.download_started, job.getName()));
    } else {
        notification.contentView.setTextViewText(R.id.status_text,
                context.getString(R.string.upload_started, job.getName()));
        notification.contentIntent = contentIntent;
    }

    notification.contentView.setProgressBar(R.id.status_progress, 100, progress, false);
    return notification;
}

From source file:org.addhen.smssync.util.Util.java

/**
 * Show notification/*from ww  w .  j  ava  2s  . c o m*/
 */
public static void showNotification(Context context) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent baseIntent = new Intent(context, MessagesTabActivity.class);

    baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    Notification notification = new Notification(R.drawable.icon, context.getString(R.string.status),
            System.currentTimeMillis());

    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, baseIntent, 0);

    notification.setLatestEventInfo(context, context.getString(R.string.app_name),
            context.getString(R.string.notification_summary), pendingIntent);

    notificationManager.notify(NOTIFY_RUNNING, notification);

}