Search in sources :

Example 46 with Notification

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

the class DeviceStorageMonitorService method sendNotification.

/**
    * This method sends a notification to NotificationManager to display
    * an error dialog indicating low disk space and launch the Installer
    * application
    */
private void sendNotification() {
    final Context context = getContext();
    if (localLOGV)
        Slog.i(TAG, "Sending low memory notification");
    //log the event to event log with the amount of free storage(in bytes) left on the device
    EventLog.writeEvent(EventLogTags.LOW_STORAGE, mFreeMem);
    //  Pack up the values and broadcast them to everyone
    Intent lowMemIntent = new Intent(StorageManager.ACTION_MANAGE_STORAGE);
    lowMemIntent.putExtra("memory", mFreeMem);
    lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    NotificationManager mNotificationMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence title = context.getText(com.android.internal.R.string.low_internal_storage_view_title);
    CharSequence details = context.getText(mIsBootImageOnDisk ? com.android.internal.R.string.low_internal_storage_view_text : com.android.internal.R.string.low_internal_storage_view_text_no_boot);
    PendingIntent intent = PendingIntent.getActivityAsUser(context, 0, lowMemIntent, 0, null, UserHandle.CURRENT);
    Notification notification = new Notification.Builder(context).setSmallIcon(com.android.internal.R.drawable.stat_notify_disk_full).setTicker(title).setColor(context.getColor(com.android.internal.R.color.system_notification_accent_color)).setContentTitle(title).setContentText(details).setContentIntent(intent).setStyle(new Notification.BigTextStyle().bigText(details)).setVisibility(Notification.VISIBILITY_PUBLIC).setCategory(Notification.CATEGORY_SYSTEM).build();
    notification.flags |= Notification.FLAG_NO_CLEAR;
    mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification, UserHandle.ALL);
    context.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
}
Also used : Context(android.content.Context) NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 47 with Notification

use of android.app.Notification in project leakcanary by square.

the class LeakCanaryInternals method showNotification.

public static void showNotification(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent pendingIntent, int notificationId) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification;
    Notification.Builder builder = //
    new Notification.Builder(context).setSmallIcon(R.drawable.leak_canary_notification).setWhen(System.currentTimeMillis()).setContentTitle(contentTitle).setContentText(contentText).setAutoCancel(true).setContentIntent(pendingIntent);
    if (SDK_INT < JELLY_BEAN) {
        notification = builder.getNotification();
    } else {
        notification = builder.build();
    }
    notificationManager.notify(notificationId, notification);
}
Also used : NotificationManager(android.app.NotificationManager) Notification(android.app.Notification)

Example 48 with Notification

use of android.app.Notification in project NotificationPeekPort by lzanita09.

the class MainActivity method sendTestNotification.

/**
     * Lock device screen and send test notification.
     */
private void sendTestNotification() {
    final DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    Handler handler = new Handler(getMainLooper());
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    final Notification.Builder builder = new Notification.Builder(this);
    builder.setSmallIcon(R.drawable.ic_launcher).setTicker(getString(R.string.diagnosis_notification_title)).setContentTitle(getString(R.string.diagnosis_notification_title_content)).setContentText(getString(R.string.diagnosis_notification_content)).setLights(Color.GREEN, 1000, 5000).setAutoCancel(true).setContentIntent(pendingIntent);
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            devicePolicyManager.lockNow();
        }
    }, LOCK_SCREEN_DELAY);
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            manager.notify(TEST_ID, builder.build());
            finish();
        }
    }, SEND_NOTIFICATION_DELAY);
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) NotificationManager(android.app.NotificationManager) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 49 with Notification

use of android.app.Notification in project NotificationPeekPort by lzanita09.

the class NotificationService method onNotificationPosted.

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    Notification postedNotification = sbn.getNotification();
    if (postedNotification.tickerText == null || sbn.isOngoing() || !sbn.isClearable() || isInBlackList(sbn)) {
        return;
    }
    if (mAppList.isInQuietHour(sbn.getPostTime())) {
        // The first notification arrived during quiet hour will unregister all sensor listeners.
        mNotificationPeek.unregisterEventListeners();
        return;
    }
    mNotificationHub.addNotification(sbn);
    if (AccessChecker.isDeviceAdminEnabled(this)) {
        mNotificationPeek.showNotification(sbn, false, mPeekTimeoutMultiplier, mSensorTimeoutMultiplier, mShowContent);
    }
}
Also used : Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 50 with Notification

use of android.app.Notification in project NotificationPeekPort by lzanita09.

the class NotificationHelper method getNotificationText.

/**
     * Get text from notification with specific field.
     *
     * @param n     StatusBarNotification object.
     * @param field StatusBarNotification extra field.
     * @return Notification text.
     */
public static String getNotificationText(StatusBarNotification n, String field) {
    String text = null;
    if (n != null) {
        Notification notification = n.getNotification();
        Bundle extras = notification.extras;
        CharSequence chars = extras.getCharSequence(field);
        text = chars != null ? chars.toString() : null;
    }
    return text;
}
Also used : Bundle(android.os.Bundle) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification)

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