Search in sources :

Example 71 with NotificationManager

use of android.app.NotificationManager in project react-native-push-notification by zo0r.

the class RNPushNotification method registerNotificationsReceiveNotificationActions.

private void registerNotificationsReceiveNotificationActions(ReadableArray actions) {
    IntentFilter intentFilter = new IntentFilter();
    // Add filter for each actions.
    for (int i = 0; i < actions.size(); i++) {
        String action = actions.getString(i);
        intentFilter.addAction(getReactApplicationContext().getPackageName() + "." + action);
    }
    getReactApplicationContext().registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle bundle = intent.getBundleExtra("notification");
            // Notify the action.
            mJsDelivery.notifyNotificationAction(bundle);
            // Dismiss the notification popup.
            NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
            int notificationID = Integer.parseInt(bundle.getString("id"));
            manager.cancel(notificationID);
        }
    }, intentFilter);
}
Also used : Context(android.content.Context) ReactContext(com.facebook.react.bridge.ReactContext) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) Bundle(android.os.Bundle) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 72 with NotificationManager

use of android.app.NotificationManager in project AdMoney by ErnestoGonAr.

the class AlarmReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    String nombre = intent.getStringExtra("NotfNombre");
    float cantidad = intent.getFloatExtra("NotfCantidad", 0);
    String fecha = intent.getStringExtra("NotfFecha");
    int frecuencia = intent.getIntExtra("NotfFrecuencia", 0);
    int id = intent.getIntExtra("NotfId", 0);
    nuevaFecha(context, nombre, cantidad, fecha, frecuencia, id);
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.admoney_logo).setTicker("Recordatorio de pagos...").setContentTitle("Pagar: " + nombre).setContentText("por la cantidad de $" + cantidad).setSound(alarmSound).setAutoCancel(true).setWhen(when).setContentIntent(pendingIntent).setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
    notificationManager.notify(id, mNotifyBuilder.build());
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri)

Example 73 with NotificationManager

use of android.app.NotificationManager in project Etar-Calendar by Etar-Group.

the class DismissAlarmsService method onHandleIntent.

@Override
public void onHandleIntent(Intent intent) {
    long eventId = intent.getLongExtra(AlertUtils.EVENT_ID_KEY, -1);
    long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1);
    long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1);
    boolean showEvent = intent.getBooleanExtra(AlertUtils.SHOW_EVENT_KEY, false);
    long[] eventIds = intent.getLongArrayExtra(AlertUtils.EVENT_IDS_KEY);
    long[] eventStarts = intent.getLongArrayExtra(AlertUtils.EVENT_STARTS_KEY);
    int notificationId = intent.getIntExtra(AlertUtils.NOTIFICATION_ID_KEY, -1);
    List<AlarmId> alarmIds = new LinkedList<AlarmId>();
    Uri uri = CalendarAlerts.CONTENT_URI;
    String selection;
    // Dismiss a specific fired alarm if id is present, otherwise, dismiss all alarms
    if (eventId != -1) {
        alarmIds.add(new AlarmId(eventId, eventStart));
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " + CalendarAlerts.EVENT_ID + "=" + eventId;
    } else if (eventIds != null && eventIds.length > 0 && eventStarts != null && eventIds.length == eventStarts.length) {
        selection = buildMultipleEventsQuery(eventIds);
        for (int i = 0; i < eventIds.length; i++) {
            alarmIds.add(new AlarmId(eventIds[i], eventStarts[i]));
        }
    } else {
        // NOTE: I don't believe that this ever happens.
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED;
    }
    GlobalDismissManager.dismissGlobally(getApplicationContext(), alarmIds);
    ContentResolver resolver = getContentResolver();
    ContentValues values = new ContentValues();
    values.put(PROJECTION[COLUMN_INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
    resolver.update(uri, values, selection, null);
    // Remove from notification bar.
    if (notificationId != -1) {
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(notificationId);
    }
    if (showEvent) {
        // Show event on Calendar app by building an intent and task stack to start
        // EventInfoActivity with AllInOneActivity as the parent activity rooted to home.
        Intent i = AlertUtils.buildEventViewIntent(this, eventId, eventStart, eventEnd);
        TaskStackBuilder.create(this).addParentStack(EventInfoActivity.class).addNextIntent(i).startActivities();
    }
}
Also used : AlarmId(com.android.calendar.alerts.GlobalDismissManager.AlarmId) ContentValues(android.content.ContentValues) NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) Uri(android.net.Uri) LinkedList(java.util.LinkedList) ContentResolver(android.content.ContentResolver)

Example 74 with NotificationManager

use of android.app.NotificationManager in project Etar-Calendar by Etar-Group.

the class SnoozeAlarmsService method onHandleIntent.

@Override
public void onHandleIntent(Intent intent) {
    long eventId = intent.getLongExtra(AlertUtils.EVENT_ID_KEY, -1);
    long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1);
    long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1);
    long snoozeDelay = intent.getLongExtra(AlertUtils.SNOOZE_DELAY_KEY, Utils.getDefaultSnoozeDelayMs(this));
    // The ID reserved for the expired notification digest should never be passed in
    // here, so use that as a default.
    int notificationId = intent.getIntExtra(AlertUtils.NOTIFICATION_ID_KEY, AlertUtils.EXPIRED_GROUP_NOTIFICATION_ID);
    if (eventId != -1) {
        ContentResolver resolver = getContentResolver();
        // Remove notification
        if (notificationId != AlertUtils.EXPIRED_GROUP_NOTIFICATION_ID) {
            NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            nm.cancel(notificationId);
        }
        // Dismiss current alarm
        Uri uri = CalendarAlerts.CONTENT_URI;
        String selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " + CalendarAlerts.EVENT_ID + "=" + eventId;
        ContentValues dismissValues = new ContentValues();
        dismissValues.put(PROJECTION[COLUMN_INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
        resolver.update(uri, dismissValues, selection, null);
        // Add a new alarm
        long alarmTime = System.currentTimeMillis() + snoozeDelay;
        ContentValues values = AlertUtils.makeContentValues(eventId, eventStart, eventEnd, alarmTime, 0);
        resolver.insert(uri, values);
        AlertUtils.scheduleAlarm(SnoozeAlarmsService.this, AlertUtils.createAlarmManager(this), alarmTime);
    }
    AlertService.updateAlertNotification(this);
    stopSelf();
}
Also used : ContentValues(android.content.ContentValues) NotificationManager(android.app.NotificationManager) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 75 with NotificationManager

use of android.app.NotificationManager in project OneSignal-Android-SDK by OneSignal.

the class OneSignal method clearOneSignalNotifications.

public static void clearOneSignalNotifications() {
    if (appContext == null) {
        Log(LOG_LEVEL.ERROR, "OneSignal.init has not been called. Could not clear notifications.");
        return;
    }
    NotificationManager notificationManager = (NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE);
    OneSignalDbHelper dbHelper = OneSignalDbHelper.getInstance(appContext);
    Cursor cursor = null;
    try {
        SQLiteDatabase readableDb = dbHelper.getReadableDbWithRetries();
        String[] retColumn = { OneSignalDbContract.NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID };
        cursor = readableDb.query(OneSignalDbContract.NotificationTable.TABLE_NAME, retColumn, OneSignalDbContract.NotificationTable.COLUMN_NAME_DISMISSED + " = 0 AND " + OneSignalDbContract.NotificationTable.COLUMN_NAME_OPENED + " = 0", null, // group by
        null, // filter by row groups
        null, // sort order
        null);
        if (cursor.moveToFirst()) {
            do {
                int existingId = cursor.getInt(cursor.getColumnIndex(OneSignalDbContract.NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID));
                notificationManager.cancel(existingId);
            } while (cursor.moveToNext());
        }
        // Mark all notifications as dismissed unless they were already opened.
        SQLiteDatabase writableDb = null;
        try {
            writableDb = dbHelper.getWritableDbWithRetries();
            writableDb.beginTransaction();
            String whereStr = NotificationTable.COLUMN_NAME_OPENED + " = 0";
            ContentValues values = new ContentValues();
            values.put(NotificationTable.COLUMN_NAME_DISMISSED, 1);
            writableDb.update(NotificationTable.TABLE_NAME, values, whereStr, null);
            writableDb.setTransactionSuccessful();
        } catch (Throwable t) {
            OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error marking all notifications as dismissed! ", t);
        } finally {
            if (writableDb != null)
                writableDb.endTransaction();
        }
        BadgeCountUpdater.updateCount(0, appContext);
    } catch (Throwable t) {
        OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error canceling all notifications! ", t);
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : ContentValues(android.content.ContentValues) NotificationManager(android.app.NotificationManager) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Aggregations

NotificationManager (android.app.NotificationManager)930 Intent (android.content.Intent)400 PendingIntent (android.app.PendingIntent)397 Notification (android.app.Notification)276 NotificationCompat (android.support.v4.app.NotificationCompat)267 NotificationChannel (android.app.NotificationChannel)129 Uri (android.net.Uri)62 Context (android.content.Context)59 SharedPreferences (android.content.SharedPreferences)41 Bitmap (android.graphics.Bitmap)41 Resources (android.content.res.Resources)39 Bundle (android.os.Bundle)36 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)35 SuppressLint (android.annotation.SuppressLint)27 TargetApi (android.annotation.TargetApi)26 TaskStackBuilder (android.app.TaskStackBuilder)25 StatusBarNotification (android.service.notification.StatusBarNotification)24 IOException (java.io.IOException)22 File (java.io.File)20 IntentFilter (android.content.IntentFilter)18