Search in sources :

Example 31 with Notification

use of android.app.Notification in project platform_frameworks_base by android.

the class CarrierActionUtils method onShowCaptivePortalNotification.

private static void onShowCaptivePortalNotification(Intent intent, Context context) {
    logd("onShowCaptivePortalNotification");
    final NotificationManager notificationMgr = context.getSystemService(NotificationManager.class);
    Intent portalIntent = new Intent(context, CaptivePortalLoginActivity.class);
    portalIntent.putExtras(intent);
    portalIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, portalIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Notification notification = getNotification(context, R.string.portal_notification_id, R.string.portal_notification_detail, pendingIntent);
    try {
        notificationMgr.notify(PORTAL_NOTIFICATION_TAG, PORTAL_NOTIFICATION_ID, notification);
    } catch (NullPointerException npe) {
        loge("setNotificationVisible: " + npe);
    }
}
Also used : NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 32 with Notification

use of android.app.Notification in project platform_frameworks_base by android.

the class CarrierActionUtils method getNotification.

private static Notification getNotification(Context context, int titleId, int textId, PendingIntent pendingIntent) {
    final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
    final Resources resources = context.getResources();
    final Bundle extras = Bundle.forPair(Notification.EXTRA_SUBSTITUTE_APP_NAME, resources.getString(R.string.android_system_label));
    Notification.Builder builder = new Notification.Builder(context).setContentTitle(resources.getString(titleId)).setContentText(String.format(resources.getString(textId), telephonyMgr.getNetworkOperatorName())).setSmallIcon(R.drawable.ic_sim_card).setColor(context.getColor(com.android.internal.R.color.system_notification_accent_color)).setOngoing(true).setPriority(Notification.PRIORITY_HIGH).setDefaults(Notification.DEFAULT_ALL).setVisibility(Notification.VISIBILITY_PUBLIC).setLocalOnly(true).setWhen(System.currentTimeMillis()).setShowWhen(false).setExtras(extras);
    if (pendingIntent != null) {
        builder.setContentIntent(pendingIntent);
    }
    return builder.build();
}
Also used : TelephonyManager(android.telephony.TelephonyManager) Bundle(android.os.Bundle) Resources(android.content.res.Resources) Notification(android.app.Notification)

Example 33 with Notification

use of android.app.Notification in project platform_frameworks_base by android.

the class CarrierActionUtils method onShowNoDataServiceNotification.

private static void onShowNoDataServiceNotification(Context context) {
    logd("onShowNoDataServiceNotification");
    final NotificationManager notificationMgr = context.getSystemService(NotificationManager.class);
    Notification notification = getNotification(context, R.string.no_data_notification_id, R.string.no_data_notification_detail, null);
    try {
        notificationMgr.notify(NO_DATA_NOTIFICATION_TAG, NO_DATA_NOTIFICATION_ID, notification);
    } catch (NullPointerException npe) {
        loge("setNotificationVisible: " + npe);
    }
}
Also used : NotificationManager(android.app.NotificationManager) Notification(android.app.Notification)

Example 34 with Notification

use of android.app.Notification in project platform_frameworks_base by android.

the class BugreportProgressService method sendBugreportNotification.

/**
     * Sends a notification indicating the bugreport has finished so use can share it.
     */
private void sendBugreportNotification(BugreportInfo info, boolean takingScreenshot) {
    // Since adding the details can take a while, do it before notifying user.
    addDetailsToZipFile(info);
    final Intent shareIntent = new Intent(INTENT_BUGREPORT_SHARE);
    shareIntent.setClass(mContext, BugreportProgressService.class);
    shareIntent.setAction(INTENT_BUGREPORT_SHARE);
    shareIntent.putExtra(EXTRA_ID, info.id);
    shareIntent.putExtra(EXTRA_INFO, info);
    final String title = mContext.getString(R.string.bugreport_finished_title, info.id);
    final String content = takingScreenshot ? mContext.getString(R.string.bugreport_finished_pending_screenshot_text) : mContext.getString(R.string.bugreport_finished_text);
    final Notification.Builder builder = newBaseNotification(mContext).setContentTitle(title).setTicker(title).setContentText(content).setContentIntent(PendingIntent.getService(mContext, info.id, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT)).setDeleteIntent(newCancelIntent(mContext, info));
    if (!TextUtils.isEmpty(info.name)) {
        builder.setSubText(info.name);
    }
    Log.v(TAG, "Sending 'Share' notification for ID " + info.id + ": " + title);
    NotificationManager.from(mContext).notify(info.id, builder.build());
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Notification(android.app.Notification)

Example 35 with Notification

use of android.app.Notification in project platform_frameworks_base by android.

the class BugreportProgressService method updateProgress.

/**
     * Updates the system notification for a given bugreport.
     */
private void updateProgress(BugreportInfo info) {
    if (info.max <= 0 || info.progress < 0) {
        Log.e(TAG, "Invalid progress values for " + info);
        return;
    }
    if (info.finished) {
        Log.w(TAG, "Not sending progress notification because bugreport has finished already (" + info + ")");
        return;
    }
    final NumberFormat nf = NumberFormat.getPercentInstance();
    nf.setMinimumFractionDigits(2);
    nf.setMaximumFractionDigits(2);
    final String percentageText = nf.format((double) info.progress / info.max);
    String title = mContext.getString(R.string.bugreport_in_progress_title, info.id);
    // TODO: Remove this workaround when notification progress is implemented on Wear.
    if (mIsWatch) {
        nf.setMinimumFractionDigits(0);
        nf.setMaximumFractionDigits(0);
        final String watchPercentageText = nf.format((double) info.progress / info.max);
        title = title + "\n" + watchPercentageText;
    }
    final String name = info.name != null ? info.name : mContext.getString(R.string.bugreport_unnamed);
    final Notification.Builder builder = newBaseNotification(mContext).setContentTitle(title).setTicker(title).setContentText(name).setProgress(info.max, info.progress, false).setOngoing(true);
    // Wear bugreport doesn't need the bug info dialog, screenshot and cancel action.
    if (!mIsWatch) {
        final Action cancelAction = new Action.Builder(null, mContext.getString(com.android.internal.R.string.cancel), newCancelIntent(mContext, info)).build();
        final Intent infoIntent = new Intent(mContext, BugreportProgressService.class);
        infoIntent.setAction(INTENT_BUGREPORT_INFO_LAUNCH);
        infoIntent.putExtra(EXTRA_ID, info.id);
        final PendingIntent infoPendingIntent = PendingIntent.getService(mContext, info.id, infoIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        final Action infoAction = new Action.Builder(null, mContext.getString(R.string.bugreport_info_action), infoPendingIntent).build();
        final Intent screenshotIntent = new Intent(mContext, BugreportProgressService.class);
        screenshotIntent.setAction(INTENT_BUGREPORT_SCREENSHOT);
        screenshotIntent.putExtra(EXTRA_ID, info.id);
        PendingIntent screenshotPendingIntent = mTakingScreenshot ? null : PendingIntent.getService(mContext, info.id, screenshotIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        final Action screenshotAction = new Action.Builder(null, mContext.getString(R.string.bugreport_screenshot_action), screenshotPendingIntent).build();
        builder.setContentIntent(infoPendingIntent).setActions(infoAction, screenshotAction, cancelAction);
    }
    if (DEBUG) {
        Log.d(TAG, "Sending 'Progress' notification for id " + info.id + " (pid " + info.pid + "): " + percentageText);
    }
    sendForegroundabledNotification(info.id, builder.build());
}
Also used : Action(android.app.Notification.Action) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) NumberFormat(java.text.NumberFormat)

Aggregations

Notification (android.app.Notification)568 PendingIntent (android.app.PendingIntent)276 Intent (android.content.Intent)253 NotificationManager (android.app.NotificationManager)128 StatusBarNotification (android.service.notification.StatusBarNotification)96 NotificationCompat (android.support.v4.app.NotificationCompat)64 Resources (android.content.res.Resources)56 Bitmap (android.graphics.Bitmap)48 Test (org.junit.Test)48 Context (android.content.Context)47 ITransientNotification (android.app.ITransientNotification)32 RemoteViews (android.widget.RemoteViews)30 RemoteException (android.os.RemoteException)24 ApplicationInfo (android.content.pm.ApplicationInfo)17 UserHandle (android.os.UserHandle)17 Date (java.util.Date)16 Uri (android.net.Uri)15 Bundle (android.os.Bundle)15 ComponentName (android.content.ComponentName)13 File (java.io.File)13