use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.
the class Tethering method showTetheredNotification.
private void showTetheredNotification(int icon) {
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager == null) {
return;
}
if (mTetheredNotification != null) {
if (mTetheredNotification.icon == icon) {
return;
}
notificationManager.cancelAsUser(null, mTetheredNotification.icon, UserHandle.ALL);
}
Intent intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings.TetherSettings");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, intent, 0, null, UserHandle.CURRENT);
Resources r = Resources.getSystem();
CharSequence title = r.getText(com.android.internal.R.string.tethered_notification_title);
CharSequence message = r.getText(com.android.internal.R.string.tethered_notification_message);
if (mTetheredNotification == null) {
mTetheredNotification = new Notification();
mTetheredNotification.when = 0;
}
mTetheredNotification.icon = icon;
mTetheredNotification.defaults &= ~Notification.DEFAULT_SOUND;
mTetheredNotification.flags = Notification.FLAG_ONGOING_EVENT;
mTetheredNotification.tickerText = title;
mTetheredNotification.setLatestEventInfo(getUiContext(), title, message, pi);
notificationManager.notifyAsUser(null, mTetheredNotification.icon, mTetheredNotification, UserHandle.ALL);
}
use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.
the class Vpn method showNotification.
private void showNotification(VpnConfig config, String label, Bitmap icon) {
if (!mEnableNotif)
return;
mStatusIntent = VpnConfig.getIntentForStatusPanel(mContext, config);
NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (nm != null) {
String title = (label == null) ? mContext.getString(R.string.vpn_title) : mContext.getString(R.string.vpn_title_long, label);
String text = (config.session == null) ? mContext.getString(R.string.vpn_text) : mContext.getString(R.string.vpn_text_long, config.session);
config.startTime = SystemClock.elapsedRealtime();
Notification notification = new Notification.Builder(mContext).setSmallIcon(R.drawable.vpn_connected).setLargeIcon(icon).setContentTitle(title).setContentText(text).setContentIntent(mStatusIntent).setDefaults(0).setOngoing(true).build();
nm.notifyAsUser(null, R.drawable.vpn_connected, notification, UserHandle.ALL);
}
}
use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.
the class ServiceRecord method postNotification.
public void postNotification() {
final int appUid = appInfo.uid;
final int appPid = app.pid;
if (foregroundId != 0 && foregroundNoti != null) {
// Do asynchronous communication with notification manager to
// avoid deadlocks.
final String localPackageName = packageName;
final int localForegroundId = foregroundId;
final Notification localForegroundNoti = foregroundNoti;
ams.mHandler.post(new Runnable() {
public void run() {
NotificationManagerService nm = (NotificationManagerService) NotificationManager.getService();
if (nm == null) {
return;
}
try {
if (localForegroundNoti.icon == 0) {
// It is not correct for the caller to supply a notification
// icon, but this used to be able to slip through, so for
// those dirty apps give it the app's icon.
localForegroundNoti.icon = appInfo.icon;
// Do not allow apps to present a sneaky invisible content view either.
localForegroundNoti.contentView = null;
localForegroundNoti.bigContentView = null;
CharSequence appName = appInfo.loadLabel(ams.mContext.getPackageManager());
if (appName == null) {
appName = appInfo.packageName;
}
Context ctx = null;
try {
ctx = ams.mContext.createPackageContext(appInfo.packageName, 0);
Intent runningIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
runningIntent.setData(Uri.fromParts("package", appInfo.packageName, null));
PendingIntent pi = PendingIntent.getActivity(ams.mContext, 0, runningIntent, PendingIntent.FLAG_UPDATE_CURRENT);
localForegroundNoti.setLatestEventInfo(ctx, ams.mContext.getString(com.android.internal.R.string.app_running_notification_title, appName), ams.mContext.getString(com.android.internal.R.string.app_running_notification_text, appName), pi);
} catch (PackageManager.NameNotFoundException e) {
localForegroundNoti.icon = 0;
}
}
if (localForegroundNoti.icon == 0) {
// being foreground.
throw new RuntimeException("icon must be non-zero");
}
int[] outId = new int[1];
nm.enqueueNotificationInternal(localPackageName, localPackageName, appUid, appPid, null, localForegroundId, localForegroundNoti, outId, userId);
} catch (RuntimeException e) {
Slog.w(ActivityManagerService.TAG, "Error showing notification for service", e);
// If it gave us a garbage notification, it doesn't
// get to be foreground.
ams.setServiceForeground(name, ServiceRecord.this, 0, null, true);
ams.crashApplication(appUid, appPid, localPackageName, "Bad notification for startForeground: " + e);
}
}
});
}
}
use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.
the class FixVibrateSetting method test.
private void test() {
Notification n = new Notification(R.drawable.stat_sys_warning, "Test notification", System.currentTimeMillis());
Intent intent = new Intent(this, FixVibrateSetting.class);
PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0);
n.setLatestEventInfo(this, "Test notification", "Test notification", pending);
n.vibrate = new long[] { 0, 700, 500, 1000 };
n.flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(1, n);
}
use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.
the class NotificationBuilderTest method sendNotification.
private void sendNotification(final int id) {
final Notification n = buildNotification(id);
mHandler.postDelayed(new Runnable() {
public void run() {
mNM.notify(NOTIFY_TAG, id, n);
}
}, mStartDelay);
}
Aggregations