Search in sources :

Example 11 with NotificationManagerCompat

use of android.support.v4.app.NotificationManagerCompat in project Conversations by siacs.

the class NotificationService method updateNotification.

public void updateNotification(final boolean notify) {
    final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
    final SharedPreferences preferences = mXmppConnectionService.getPreferences();
    if (notifications.size() == 0) {
        notificationManager.cancel(NOTIFICATION_ID);
    } else {
        if (notify) {
            this.markLastNotification();
        }
        final Builder mBuilder;
        if (notifications.size() == 1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            mBuilder = buildSingleConversations(notifications.values().iterator().next());
            modifyForSoundVibrationAndLight(mBuilder, notify, preferences);
            notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
        } else {
            mBuilder = buildMultipleConversation();
            modifyForSoundVibrationAndLight(mBuilder, notify, preferences);
            notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
            for (Map.Entry<String, ArrayList<Message>> entry : notifications.entrySet()) {
                Builder singleBuilder = buildSingleConversations(entry.getValue());
                singleBuilder.setGroup(CONVERSATIONS_GROUP);
                modifyForSoundVibrationAndLight(singleBuilder, notify, preferences);
                notificationManager.notify(entry.getKey(), NOTIFICATION_ID, singleBuilder.build());
            }
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Builder(android.support.v4.app.NotificationCompat.Builder) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 12 with NotificationManagerCompat

use of android.support.v4.app.NotificationManagerCompat in project Android-Wear-Codelab by fnk0.

the class MainActivity method sendNotification.

// Define the method to send the notifications with the same name from the Android onClick from the XML Layout
public void sendNotification(View view) {
    // id- An identifier for this notification unique within your application.
    int notificationId = 001;
    // Common elements for all our notifications
    String eventTitle = "Sample Notification";
    String eventText = "Text for the notification.";
    String intentExtra = "This is an extra String!";
    String eventDescription = "This is supposed to  be a content that will not fit the normal content screen" + " usually a bigger text, by example a long text message or email.";
    // Build intent for notification content
    Intent viewIntent = new Intent(this, MainActivity.class);
    PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, 0);
    // Specify the 'big view' content to display the long
    // event description that may not fit the normal content text.
    NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
    NotificationCompat.Builder mBuilder = null;
    NotificationCompat mNotification = null;
    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    switch(view.getId()) {
        case R.id.simpleNotification:
            mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_wear_notification).setContentTitle(eventTitle).setContentText(eventText).setAutoCancel(// This flag makes the notification disappear when the user clicks on it!
            true).setContentIntent(viewPendingIntent);
            break;
        case R.id.bigNotification:
            // bigText will override setContentText
            bigStyle.bigText(eventDescription);
            // bigContentTitle Override the contentTitle
            bigStyle.setBigContentTitle("Override Title");
            mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_wear_notification).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_sample_codelab)).setContentTitle(// This is unnecessary for the big notification if you use bigText
            eventTitle).setContentText(// Unnecessary if setBigContentTitle is Overriden
            eventText).setContentIntent(viewPendingIntent).setAutoCancel(true).setStyle(bigStyle);
            break;
        case R.id.bigNotificationWithAction:
            // Intent pointing to our second activity
            Intent photoIntent = new Intent(this, SecondActivity.class);
            // Set the extra message that will open in the next activity
            photoIntent.putExtra("message", intentExtra);
            // Send the photo to the next activity
            photoIntent.putExtra("photo", R.drawable.ic_sample_codelab);
            // set a new pending intent
            PendingIntent photoPending = PendingIntent.getActivity(this, 0, photoIntent, 0);
            bigStyle.setBigContentTitle("Mr. Flowers");
            bigStyle.bigText("Check out this picture!! :D");
            mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_wear_notification).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_sample_codelab)).setContentIntent(// This will be the default OPEN button.
            viewPendingIntent).addAction(R.drawable.ic_photo, "See Photo", // This is our extra action. With an Extra Icon and pointing to the other PendingIntent
            photoPending).setAutoCancel(true).setStyle(bigStyle);
            break;
        case R.id.sendCustomNotification:
            mBuilder = new NotificationCompat.Builder(this).setSmallIcon(mCustomIcon).setContentTitle(mCustomTitle.getText().toString()).setContentText(mCustomMessage.getText().toString()).setAutoCancel(true).setContentIntent(viewPendingIntent);
            // This is an example of the NEW WearableNotification SDK.
            // The WearableNotification has special functionality for wearable devices
            // By example the setHintHideIcon hides the APP ICON from the notification.
            // This code is now Up to date thanks to Romin Irani!! Thanks!
            NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(mBuilder.build());
            wearableExtender.setHintHideIcon(!showIcon);
            wearableExtender.extend(mBuilder);
            break;
    }
    notificationManager.notify(notificationId, mBuilder.build());
}
Also used : NotificationManagerCompat(android.preview.support.v4.app.NotificationManagerCompat) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 13 with NotificationManagerCompat

use of android.support.v4.app.NotificationManagerCompat in project RSAndroidApp by RailwayStations.

the class NearbyNotificationService method onDestroy.

@Override
public void onDestroy() {
    Log.i(TAG, "Service gets destroyed");
    try {
        notificationState = NotificationState.OFF;
        cancelNotification();
        stopLocationUpdates();
    } catch (Throwable t) {
        Log.wtf(TAG, "Unknown problem when trying to de-register from GPS updates", t);
    }
    googleApiClient.disconnect();
    // Cancel the ongoing notification
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.cancel(ONGOING_NOTIFICATION_ID);
    super.onDestroy();
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat)

Example 14 with NotificationManagerCompat

use of android.support.v4.app.NotificationManagerCompat in project RSAndroidApp by RailwayStations.

the class NearbyNotificationService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // set internal flag to avoid multi-starting
    if (intent == null || intent.getBooleanExtra(ONLY_WITHOUT_PHOTO, true)) {
        notificationState = NotificationState.ONLY_WITHOUT_PHOTO;
    } else {
        notificationState = NotificationState.ALL;
    }
    cancelNotification();
    Log.i(TAG, "Received start command");
    // connect google services
    if (!googleApiClient.isConnected()) {
        googleApiClient.connect();
    }
    final int messageId = notificationState.onlyWithoutPhoto() ? R.string.nearby_notification_active_only_without_photo : R.string.nearby_notification_active;
    // show a permanent notification to indicate that position detection is running
    final Notification ongoingNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(messageId)).setOngoing(true).setLocalOnly(true).build();
    final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(ONGOING_NOTIFICATION_ID, ongoingNotification);
    return START_STICKY;
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) NotificationCompat(android.support.v4.app.NotificationCompat) Notification(android.app.Notification)

Example 15 with NotificationManagerCompat

use of android.support.v4.app.NotificationManagerCompat in project RSAndroidApp by RailwayStations.

the class NearbyBahnhofNotificationManager method destroy.

public void destroy() {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.cancel(NOTIFICATION_ID);
    notificationStation = null;
    context = null;
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat)

Aggregations

NotificationManagerCompat (android.support.v4.app.NotificationManagerCompat)38 NotificationCompat (android.support.v4.app.NotificationCompat)17 PendingIntent (android.app.PendingIntent)15 Intent (android.content.Intent)15 SharedPreferences (android.content.SharedPreferences)7 PowerManager (android.os.PowerManager)7 Bitmap (android.graphics.Bitmap)6 AppSettings (com.klinker.android.twitter.settings.AppSettings)6 Notification (android.app.Notification)5 Context (android.content.Context)4 Cursor (android.database.Cursor)4 RemoteInput (android.support.v4.app.RemoteInput)4 Bundle (android.os.Bundle)3 ComponentName (android.content.ComponentName)2 ContentResolver (android.content.ContentResolver)2 ContentValues (android.content.ContentValues)2 Uri (android.net.Uri)2 Builder (android.support.v4.app.NotificationCompat.Builder)2 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)2 ArrayList (java.util.ArrayList)2