Search in sources :

Example 21 with NotificationManager

use of android.app.NotificationManager in project android_frameworks_base by ParanoidAndroid.

the class TestAlertActivity method onPause.

@Override
public void onPause() {
    super.onPause();
    Log.d("StatusBarTest", "onPause: Canceling notification id=" + mId);
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancel(mId);
    finish();
}
Also used : NotificationManager(android.app.NotificationManager)

Example 22 with NotificationManager

use of android.app.NotificationManager in project GT by Tencent.

the class NotificationHelper method notify.

// 1.实例化Notification类
// 2.设置Notification对象的icon,通知文字,声音
// 3.实例化PendingIntent类,作为控制点击通知后显示内容的对象
// 4.加载PendingIntent对象到Notification对象(设置 打开通知抽屉后的 标题/内容)
// 5.获得 NotificationManager对象
// 6.使用NotificationManager对象显示通知
/**
	 * 发布通知
	 * 
	 * @param c
	 *            上下文
	 * @param notifyId
	 *            通知标识id
	 * @param n
	 *            通知对象
	 */
public static void notify(Context c, int notifyId, Notification n) {
    final NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
    // 显示通知
    nm.notify(notifyId, n);
}
Also used : NotificationManager(android.app.NotificationManager)

Example 23 with NotificationManager

use of android.app.NotificationManager in project SeriesGuide by UweTrottmann.

the class TraktCredentials method setCredentialsInvalid.

/**
     * Removes the current trakt access token (but not the username), so {@link #hasCredentials()}
     * will return {@code false}, and shows a notification asking the user to re-connect.
     */
public synchronized void setCredentialsInvalid() {
    if (!mHasCredentials) {
        // already invalidated credentials
        return;
    }
    removeAccessToken();
    Timber.e("trakt credentials invalid, removed access token");
    NotificationCompat.Builder nb = new NotificationCompat.Builder(mContext);
    nb.setSmallIcon(R.drawable.ic_notification);
    nb.setContentTitle(mContext.getString(R.string.trakt_reconnect));
    nb.setContentText(mContext.getString(R.string.trakt_reconnect_details));
    nb.setTicker(mContext.getString(R.string.trakt_reconnect_details));
    PendingIntent intent = TaskStackBuilder.create(mContext).addNextIntent(new Intent(mContext, ShowsActivity.class)).addNextIntent(new Intent(mContext, ConnectTraktActivity.class)).getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    nb.setContentIntent(intent);
    nb.setAutoCancel(true);
    nb.setColor(ContextCompat.getColor(mContext, R.color.accent_primary));
    nb.setPriority(NotificationCompat.PRIORITY_HIGH);
    nb.setCategory(NotificationCompat.CATEGORY_ERROR);
    NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(SgApp.NOTIFICATION_TRAKT_AUTH_ID, nb.build());
}
Also used : ShowsActivity(com.battlelancer.seriesguide.ui.ShowsActivity) NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 24 with NotificationManager

use of android.app.NotificationManager in project Fairphone by Kwamecorp.

the class UpdaterService method setNotification.

private void setNotification() {
    Context context = getApplicationContext();
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.fairphone_updater_tray_icon_small).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.fairphone_updater_tray_icon)).setContentTitle(context.getResources().getString(R.string.app_name)).setContentText(getResources().getString(R.string.fairphoneUpdateMessage));
    Intent resultIntent = new Intent(context, FairphoneUpdater.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(FairphoneUpdater.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    Notification notificationWhileRunnig = builder.build();
    // Add notification
    manager.notify(0, notificationWhileRunnig);
    //to update the activity
    Intent updateIntent = new Intent(FairphoneUpdater.FAIRPHONE_UPDATER_NEW_VERSION_RECEIVED);
    sendBroadcast(updateIntent);
}
Also used : Context(android.content.Context) NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.app.TaskStackBuilder) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) Notification(android.app.Notification)

Example 25 with NotificationManager

use of android.app.NotificationManager in project XPrivacy by M66B.

the class UpdateService method notifyProgress.

private static void notifyProgress(Context context, int id, String format, int percentage) {
    String message = String.format(format, String.format("%d %%", percentage));
    Util.log(null, Log.WARN, message);
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setContentTitle(context.getString(R.string.app_name));
    builder.setContentText(message);
    builder.setWhen(System.currentTimeMillis());
    builder.setAutoCancel(percentage == 100);
    builder.setOngoing(percentage < 100);
    Notification notification = builder.build();
    notificationManager.notify(id, notification);
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Notification(android.app.Notification)

Aggregations

NotificationManager (android.app.NotificationManager)374 Intent (android.content.Intent)187 PendingIntent (android.app.PendingIntent)184 Notification (android.app.Notification)147 NotificationCompat (android.support.v4.app.NotificationCompat)107 Context (android.content.Context)32 Bitmap (android.graphics.Bitmap)24 Uri (android.net.Uri)23 Resources (android.content.res.Resources)22 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)20 TaskStackBuilder (android.app.TaskStackBuilder)15 Bundle (android.os.Bundle)15 StatusBarNotification (android.service.notification.StatusBarNotification)15 Random (java.util.Random)14 BitmapFactory (android.graphics.BitmapFactory)13 SharedPreferences (android.content.SharedPreferences)12 ComponentName (android.content.ComponentName)10 IntentFilter (android.content.IntentFilter)9 ArrayList (java.util.ArrayList)9 Date (java.util.Date)9