Search in sources :

Example 6 with NotificationChannel

use of android.app.NotificationChannel in project run-wallet-android by runplay.

the class NotificationHelper method createNotificationChannel.

@RequiresApi(api = Build.VERSION_CODES.O)
private static void createNotificationChannel(Context context) {
    NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
    NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, context.getResources().getString(R.string.app_name), NotificationManager.IMPORTANCE_MIN);
    notificationManager.createNotificationChannel(channel);
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) RequiresApi(android.support.annotation.RequiresApi)

Example 7 with NotificationChannel

use of android.app.NotificationChannel in project xabber-android by redsolution.

the class NotificationManager method createNotificationChannel.

@RequiresApi(api = Build.VERSION_CODES.O)
public String createNotificationChannel() {
    String channelId = "xabber_notification";
    String channelName = "Xabber Notification";
    @SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(channelId, channelName, android.app.NotificationManager.IMPORTANCE_HIGH);
    android.app.NotificationManager service = (android.app.NotificationManager) Application.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
    if (service != null)
        service.createNotificationChannel(channel);
    return channelId;
}
Also used : NotificationChannel(android.app.NotificationChannel) SuppressLint(android.annotation.SuppressLint) RequiresApi(android.support.annotation.RequiresApi)

Example 8 with NotificationChannel

use of android.app.NotificationChannel in project mobile-center-sdk-android by Microsoft.

the class PushNotifier method handleNotification.

/**
 * Builds a push notification using the given context and intent.
 *
 * @param context    The current context.
 * @param pushIntent The intent that is associated with the push.
 */
static void handleNotification(Context context, Intent pushIntent) throws RuntimeException {
    context = context.getApplicationContext();
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    /* Generate notification identifier using the hash of the Google message id. */
    String messageId = PushIntentUtils.getGoogleMessageId(pushIntent);
    if (messageId == null) {
        AppCenterLog.error(LOG_TAG, "Push notification did not" + "contain Google message ID; aborting notification processing.");
        return;
    }
    int notificationId = messageId.hashCode();
    /* Click action. */
    PackageManager packageManager = context.getPackageManager();
    Intent actionIntent = packageManager.getLaunchIntentForPackage(context.getPackageName());
    if (actionIntent != null) {
        actionIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        Map<String, String> customData = PushIntentUtils.getCustomData(pushIntent);
        for (String key : customData.keySet()) {
            actionIntent.putExtra(key, customData.get(key));
        }
        /* Set the message ID in the intent. */
        PushIntentUtils.setGoogleMessageId(messageId, actionIntent);
    } else {
        /* If no launcher, just create a placeholder action as the field is mandatory. */
        actionIntent = new Intent();
    }
    /* Get text. Use app name for title if title is missing. */
    String notificationTitle = PushIntentUtils.getTitle(pushIntent);
    if (notificationTitle == null || notificationTitle.isEmpty()) {
        notificationTitle = AppNameHelper.getAppName(context);
    }
    String notificationMessage = PushIntentUtils.getMessage(pushIntent);
    /* Start building notification. */
    Notification.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
        /* Get channel. */
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
        /* Create or update channel. */
        // noinspection ConstantConditions
        notificationManager.createNotificationChannel(channel);
        /* And associate to notification. */
        builder = new Notification.Builder(context, channel.getId());
    } else {
        builder = getOldNotificationBuilder(context);
    }
    /* Set color. */
    setColor(pushIntent, builder);
    /* Set icon. */
    setIcon(context, pushIntent, builder);
    /* Set sound. */
    setSound(context, pushIntent, builder);
    /* Texts */
    builder.setContentTitle(notificationTitle).setContentText(notificationMessage).setWhen(System.currentTimeMillis());
    /* Click action. Reuse notification id for simplicity. */
    PendingIntent contentIntent = PendingIntent.getActivity(context, notificationId, actionIntent, 0);
    builder.setContentIntent(contentIntent);
    /* Build method depends on versions. */
    Notification notification;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notification = builder.build();
    } else {
        notification = getOldNotification(builder);
    }
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    // noinspection ConstantConditions
    notificationManager.notify(notificationId, notification);
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 9 with NotificationChannel

use of android.app.NotificationChannel in project android-UniversalMusicPlayer by googlesamples.

the class MediaNotificationManager method createNotificationChannel.

/**
 * Creates Notification Channel. This is required in Android O+ to display notifications.
 */
@RequiresApi(Build.VERSION_CODES.O)
private void createNotificationChannel() {
    if (mNotificationManager.getNotificationChannel(CHANNEL_ID) == null) {
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, mService.getString(R.string.notification_channel), NotificationManager.IMPORTANCE_LOW);
        notificationChannel.setDescription(mService.getString(R.string.notification_channel_description));
        mNotificationManager.createNotificationChannel(notificationChannel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) RequiresApi(android.support.annotation.RequiresApi)

Example 10 with NotificationChannel

use of android.app.NotificationChannel in project Talon-for-Twitter by klinker24.

the class App method initChannel.

public void initChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        nm.createNotificationChannel(new NotificationChannel(TALON_SERVICE_CHANNEL_ID, TALON_SERVICE_CHANNEL_DESCRIPTION, NotificationManager.IMPORTANCE_DEFAULT));
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Aggregations

NotificationChannel (android.app.NotificationChannel)12 NotificationManager (android.app.NotificationManager)8 Intent (android.content.Intent)4 RequiresApi (android.support.annotation.RequiresApi)4 PendingIntent (android.app.PendingIntent)3 SuppressLint (android.annotation.SuppressLint)2 Notification (android.app.Notification)2 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Sensor (android.hardware.Sensor)1 SensorManager (android.hardware.SensorManager)1 AudioAttributes (android.media.AudioAttributes)1 AppConfiguration (com.github.moko256.twicalico.config.AppConfiguration)1 TokenSQLiteOpenHelper (com.github.moko256.twicalico.database.TokenSQLiteOpenHelper)1 AccessToken (com.github.moko256.twicalico.entity.AccessToken)1 ExceptionNotification (com.github.moko256.twicalico.notification.ExceptionNotification)1 Stopwatch (com.google.common.base.Stopwatch)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1