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);
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations