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