Search in sources :

Example 46 with NotificationManager

use of android.app.NotificationManager in project ride-read-android by Ride-Read.

the class NotificationUtils method showNotification.

public static void showNotification(Context context, String title, String content, String sound, Intent intent) {
    intent.setFlags(0);
    int notificationId = (new Random()).nextInt();
    PendingIntent contentIntent = PendingIntent.getBroadcast(context, notificationId, intent, 0);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.notification_icon).setContentTitle(title).setAutoCancel(true).setContentIntent(contentIntent).setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND).setContentText(content).setPriority(Notification.PRIORITY_HIGH);
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    if (sound != null && sound.trim().length() > 0) {
        notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + sound);
    }
    manager.notify(notificationId, notification);
}
Also used : Random(java.util.Random) NotificationManager(android.app.NotificationManager) NotificationCompat(com.avos.avospush.notification.NotificationCompat) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 47 with NotificationManager

use of android.app.NotificationManager in project Rocket.Chat.Android by RocketChat.

the class PushNotificationHandler method createNotification.

public void createNotification(Context context, Bundle extras) {
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(context);
    String packageName = context.getPackageName();
    Resources resources = context.getResources();
    String hostname = getHostname(extras);
    String roomId = getRoomId(extras);
    int notId = parseInt(NOT_ID, extras);
    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra(PUSH_BUNDLE, extras);
    notificationIntent.putExtra(NOT_ID, notId);
    if (hostname != null && roomId != null && isValidHostname(context, hostname)) {
        notificationIntent.putExtra(HOSTNAME, hostname);
        notificationIntent.putExtra(ROOM_ID, roomId);
    }
    int requestCode = random.nextInt();
    PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()).setContentTitle(fromHtml(extras.getString(TITLE))).setTicker(fromHtml(extras.getString(TITLE))).setContentIntent(contentIntent).setAutoCancel(true);
    SharedPreferences prefs = context.getSharedPreferences(PushConstants.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
    String localIcon = prefs.getString(ICON, null);
    String localIconColor = prefs.getString(ICON_COLOR, null);
    boolean soundOption = prefs.getBoolean(SOUND, true);
    boolean vibrateOption = prefs.getBoolean(VIBRATE, true);
    Log.d(LOG_TAG, "stored icon=" + localIcon);
    Log.d(LOG_TAG, "stored iconColor=" + localIconColor);
    Log.d(LOG_TAG, "stored sound=" + soundOption);
    Log.d(LOG_TAG, "stored vibrate=" + vibrateOption);
    /*
         * Notification Vibration
         */
    setNotificationVibration(extras, vibrateOption, notificationBuilder);
    /*
         * Notification Icon Color
         *
         * Sets the small-icon background color of the notification.
         * To use, add the `iconColor` key to plugin android options
         *
         */
    setNotificationIconColor(extras.getString("color"), notificationBuilder, localIconColor);
    /*
         * Notification Icon
         *
         * Sets the small-icon of the notification.
         *
         * - checks the plugin options for `icon` key
         * - if none, uses the application icon
         *
         * The icon value must be a string that maps to a drawable resource.
         * If no resource is found, falls
         *
         */
    setNotificationSmallIcon(context, extras, packageName, resources, notificationBuilder, localIcon);
    /*
         * Notification Large-Icon
         *
         * Sets the large-icon of the notification
         *
         * - checks the gcm data for the `image` key
         * - checks to see if remote image, loads it.
         * - checks to see if assets image, Loads It.
         * - checks to see if resource image, LOADS IT!
         * - if none, we don't set the large icon
         *
         */
    setNotificationLargeIcon(context, extras, packageName, resources, notificationBuilder);
    /*
         * Notification Sound
         */
    if (soundOption) {
        setNotificationSound(context, extras, notificationBuilder);
    }
    /*
         *  LED Notification
         */
    setNotificationLedColor(extras, notificationBuilder);
    /*
         *  Priority Notification
         */
    setNotificationPriority(extras, notificationBuilder);
    /*
         * Notification message
         */
    setNotificationMessage(notId, extras, notificationBuilder);
    /*
         * Notification count
         */
    setNotificationCount(context, extras, notificationBuilder);
    /*
         * Notification count
         */
    setVisibility(context, extras, notificationBuilder);
    /*
         * Notification add actions
         */
    createActions(context, extras, notificationBuilder, resources, packageName, notId);
    mNotificationManager.notify(appName, notId, notificationBuilder.build());
}
Also used : NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent)

Example 48 with NotificationManager

use of android.app.NotificationManager in project Rocket.Chat.Android by RocketChat.

the class BackgroundActionButtonHandler method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    Log.d(LOG_TAG, "BackgroundActionButtonHandler = " + extras);
    int notId = intent.getIntExtra(NOT_ID, 0);
    Log.d(LOG_TAG, "not id = " + notId);
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(GCMIntentService.getAppName(context), notId);
    if (extras == null) {
        return;
    }
    Bundle originalExtras = extras.getBundle(PUSH_BUNDLE);
    originalExtras.putBoolean(FOREGROUND, false);
    originalExtras.putBoolean(COLDSTART, false);
    originalExtras.putString(ACTION_CALLBACK, extras.getString(CALLBACK));
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput != null) {
        String inputString = remoteInput.getCharSequence(INLINE_REPLY).toString();
        Log.d(LOG_TAG, "response: " + inputString);
        originalExtras.putString(INLINE_REPLY, inputString);
    }
}
Also used : NotificationManager(android.app.NotificationManager) Bundle(android.os.Bundle)

Example 49 with NotificationManager

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

the class MainActivity method sendNotification.

private void sendNotification(int count) {
    Notification.Builder builder = new Notification.Builder(this).setContentTitle(String.format("%s OSU available", count)).setContentText("Choose one to connect").setSmallIcon(android.R.drawable.ic_dialog_info).setAutoCancel(false);
    Intent resultIntent = new Intent(this, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
}
Also used : NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.app.TaskStackBuilder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) Notification(android.app.Notification)

Example 50 with NotificationManager

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

the class MainActivity method sendNotificationMessage.

private void sendNotificationMessage(String title) {
    Notification.Builder builder = new Notification.Builder(this).setContentTitle(title).setContentText("Click to dismiss.").setSmallIcon(android.R.drawable.ic_dialog_info).setAutoCancel(true);
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_MESSAGE_ID, builder.build());
}
Also used : NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.app.TaskStackBuilder) Notification(android.app.Notification)

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