Example usage for android.app NotificationManager IMPORTANCE_HIGH

List of usage examples for android.app NotificationManager IMPORTANCE_HIGH

Introduction

In this page you can find the example usage for android.app NotificationManager IMPORTANCE_HIGH.

Prototype

int IMPORTANCE_HIGH

To view the source code for android.app NotificationManager IMPORTANCE_HIGH.

Click Source Link

Document

Higher notification importance: shows everywhere, makes noise and peeks.

Usage

From source file:com.cryart.sabbathschool.misc.SSReminderService.java

@Override
public boolean onStartJob(JobParameters job) {
    Context context = getBaseContext();
    SSReminder.scheduleAlarms(context);//from   w w w  .j a v a2  s. c  o m
    try {
        String channelId = "ss_notification_channel";
        String channelName = getString(R.string.app_name);

        NotificationManager _SSNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel mChannel = new NotificationChannel(channelId, channelName, importance);
            _SSNotificationManager.createNotificationChannel(mChannel);
        }
        Intent _SSContentIntent = new Intent(context, SSSplashActivity.class);

        Intent _SSShareIntent = new Intent();

        _SSContentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        _SSShareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        _SSShareIntent.setAction(Intent.ACTION_SEND);
        _SSShareIntent.putExtra(Intent.EXTRA_TEXT, "");

        _SSShareIntent.setType("*/*");

        PendingIntent _SSPendingContentIntent = PendingIntent.getActivity(context, 0, _SSContentIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        PendingIntent _SSPendingShareIntent = PendingIntent.getActivity(context, 0,
                Intent.createChooser(_SSShareIntent, context.getString(R.string.ss_share)),
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder _SSNotificationBuilder = new NotificationCompat.Builder(context,
                "ss_notification_channel").setSmallIcon(R.mipmap.ic_stat_notification)
                        .setContentTitle(context.getString(R.string.ss_app_name))
                        .setColor(Color.parseColor(SSColorTheme.getInstance().getColorPrimary()))
                        .addAction(0, context.getString(R.string.ss_menu_read_now), _SSPendingContentIntent)
                        .addAction(0, context.getString(R.string.ss_share), _SSPendingShareIntent)
                        .setAutoCancel(true).setVibrate(new long[] { 1000, 1000 })
                        .setContentIntent(_SSPendingContentIntent)
                        .setContentText(context.getString(R.string.ss_settings_reminder_text));

        _SSNotificationManager.notify(1, _SSNotificationBuilder.build());
    } catch (Exception e) {
        Crashlytics.log(e.getMessage());
    }

    return false; // Answers the question: "Is there still work going on?"
}

From source file:chat.viska.android.Application.java

private void initializeNotificationChannels() {
    if (Build.VERSION.SDK_INT >= 26) {
        final NotificationManager manager = getSystemService(NotificationManager.class);

        final NotificationChannel systemChannel = new NotificationChannel(KEY_NOTIF_CHANNEL_SYSTEM,
                getString(R.string.title_notif_channel_system), NotificationManager.IMPORTANCE_LOW);
        systemChannel.setDescription(getString(R.string.desc_notif_channel_system));
        systemChannel.enableVibration(false);
        systemChannel.enableLights(false);
        systemChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        systemChannel.setShowBadge(false);
        manager.createNotificationChannel(systemChannel);

        final NotificationChannel messagingChannel = new NotificationChannel(KEY_NOTIF_CHANNEL_MESSAGES,
                getString(R.string.title_notif_channel_messaging), NotificationManager.IMPORTANCE_HIGH);
        systemChannel.setDescription(getString(R.string.desc_notif_channel_messaging));
        systemChannel.enableVibration(true);
        systemChannel.enableLights(true);
        systemChannel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
        systemChannel.setShowBadge(true);
        manager.createNotificationChannel(messagingChannel);
    }/*ww  w . j  a  v a  2 s.  c o m*/
}

From source file:com.sxt.chat.utils.NotificationHelper.java

/**
 * ?/*  w  ww.  j a v  a 2s .  c  o m*/
 * <p>
 * note : notify() ? ???,?? so, Create?
 */
public NotificationHelper(Context ctx) {
    super(ctx);
    context = ctx;
    soundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notify_message);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        AudioAttributes att = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH).build();
        NotificationChannel channel = new NotificationChannel(DEFAULT_CHANNEL, "Channel",
                NotificationManager.IMPORTANCE_HIGH);
        channel.setSound(soundUri, att);
        channel.setLightColor(Color.YELLOW);
        channel.setShowBadge(true);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        getManager().createNotificationChannel(channel);

        NotificationChannel chanCustom = new NotificationChannel(CUSTOM_NOTIFY_CHANNEL, "Custom Layout Channel",
                NotificationManager.IMPORTANCE_HIGH);
        channel.setSound(soundUri, att);
        chanCustom.setLightColor(Color.RED);
        chanCustom.setShowBadge(true);
        chanCustom.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        getManager().createNotificationChannel(chanCustom);
    }
}

From source file:androidx.navigation.testapp.AndroidFragment.java

@Override
public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    TextView tv = view.findViewById(R.id.text);
    tv.setText(getArguments().getString("myarg"));

    Button b = view.findViewById(R.id.send_notification);
    b.setOnClickListener(new View.OnClickListener() {
        @Override/*from w  ww.  j av  a2s . c om*/
        public void onClick(View v) {
            EditText editArgs = view.findViewById(R.id.edit_args);
            Bundle args = new Bundle();
            args.putString("myarg", editArgs.getText().toString());
            PendingIntent deeplink = Navigation.findNavController(v).createDeepLink()
                    .setDestination(R.id.android).setArguments(args).createPendingIntent();
            NotificationManager notificationManager = (NotificationManager) requireContext()
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                notificationManager.createNotificationChannel(
                        new NotificationChannel("deeplink", "Deep Links", NotificationManager.IMPORTANCE_HIGH));
            }
            NotificationCompat.Builder builder = new NotificationCompat.Builder(requireContext(), "deeplink")
                    .setContentTitle("Navigation").setContentText("Deep link to Android")
                    .setSmallIcon(R.drawable.ic_android).setContentIntent(deeplink).setAutoCancel(true);
            notificationManager.notify(0, builder.build());
        }
    });
}

From source file:tm.android.chronos.services.TimerRunner.java

private void createNotification(long duration) {
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    String channelId = "channel-01";

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        String channelName = "Chronos Channel";
        int importance = NotificationManager.IMPORTANCE_HIGH;
        NotificationChannel mChannel = new NotificationChannel(channelId, channelName, importance);
        notificationManager.createNotificationChannel(mChannel);
    }//w ww.  j ava  2s . c  o  m

    int min = (int) (duration / 60000);
    if (Units.hasNoResources())
        Units.setResources(context.getResources());
    String text = Units.getLocalizedTextWithParams("timer_notification", min + "", (min > 1 ? "s" : ""));//"Timer of " + min + " minute" + (min > 1 ? "s" : "") + " is finished";
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, channelId)
            .setSmallIcon(R.drawable.icon)
            .setContentTitle(context.getResources().getString(R.string.app_name_timer)).setContentText(text)
            .setPriority(NotificationCompat.PRIORITY_MAX)
            // Set the intent that will fire when the user taps the notification
            .setContentIntent(pendingIntent).setAutoCancel(true).setCategory(NotificationCompat.CATEGORY_ALARM);

    notificationManager.notify(0, mBuilder.build());
}

From source file:com.tourmaline.example.helpers.Alerts.java

public static void show(final Context context, final Type type) {
    final NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    String channelId = "";
    String channelTitle = "";
    String notifTitle = "";
    String notifText = context.getString(R.string.app_name) + " "
            + context.getString(R.string.permission_notif_text);
    int smallIconRes = R.mipmap.ic_warning_white;
    int largeIconRes = 0;
    int notifId = 0;

    switch (type) {
    case GPS: {/* w  ww.  j av  a 2 s  . c  o m*/
        channelId = NOTIF_CHANNEL_ID_GPS;
        channelTitle = context.getString(R.string.gps_notif_title);
        notifTitle = context.getString(R.string.gps_notif_title);
        largeIconRes = R.mipmap.ic_location_off_black;
        notifId = NOTIF_ID_GPS;
        break;
    }
    case PERMISSION: {
        channelId = NOTIF_CHANNEL_ID_PERMISSION;
        channelTitle = context.getString(R.string.permission_notif_title);
        notifTitle = context.getString(R.string.permission_notif_title);
        largeIconRes = R.mipmap.ic_location_off_black;
        notifId = NOTIF_ID_PERMISSION;
        break;
    }
    case POWER: {
        channelId = NOTIF_CHANNEL_ID_POWER;
        channelTitle = context.getString(R.string.power_notif_title);
        notifTitle = context.getString(R.string.power_notif_title);
        largeIconRes = R.mipmap.ic_battery_alert_black;
        notifId = NOTIF_ID_POWER;
        break;
    }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final NotificationChannel channel = new NotificationChannel(channelId, channelTitle,
                NotificationManager.IMPORTANCE_HIGH);
        channel.setShowBadge(true);
        notificationManager.createNotificationChannel(channel);
    }

    final Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), largeIconRes);

    final Notification note = new NotificationCompat.Builder(context, channelId).setContentTitle(notifTitle)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(notifText)).setSmallIcon(smallIconRes)
            .setLargeIcon(largeIcon).setVisibility(VISIBILITY_SECRET)
            .setPriority(NotificationCompat.PRIORITY_MAX).build();

    notificationManager.notify(notifId, note);

}

From source file:com.clanofthecloud.cotcpushnotifications.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from w  w w.j  a  v a  2 s.  co  m*/
 */
private void sendNotification(String message) {
    Activity currentAct = UnityPlayer.currentActivity;
    Class activityToOpen = currentAct != null ? currentAct.getClass() : UnityPlayerActivity.class;
    Intent intent = new Intent(this, activityToOpen);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    ApplicationInfo ai = null;
    try {
        ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        int notificationIcon = ai.metaData.getInt("cotc.GcmNotificationIcon", -1);
        if (notificationIcon == -1) {
            Log.e(TAG,
                    "!!!!!!!!! cotc.GcmNotificationIcon not configured in manifest, push notifications won't work !!!!!!!!!");
            return;
        }
        int notificationLargeIcon = ai.metaData.getInt("cotc.GcmNotificationLargeIcon", -1);
        if (notificationLargeIcon == -1) {
            Log.e(TAG, "There is no large icon for push notifs, will only use default icon");
            return;
        }

        String pushNotifName = ai.metaData.getString("cotc.GcmNotificationTitle");
        if (pushNotifName == null) {
            Log.e(TAG,
                    "!!!!!!!!! cotc.GcmNotificationTitle not configured in manifest, push notifications won't work !!!!!!!!!");
            return;
        }

        if (notifManager == null)
            notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel channel = new NotificationChannel("CotC Channel", "CotC Channel", importance);
            channel.setDescription("CotC Channel");
            notifManager.createNotificationChannel(channel);
            notificationBuilder = new NotificationCompat.Builder(this, "CotC Channel");
        } else
            notificationBuilder = new NotificationCompat.Builder(this);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        notificationBuilder.setSmallIcon(notificationIcon).setContentTitle(pushNotifName)
                .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
                .setContentIntent(pendingIntent).setPriority(Notification.PRIORITY_HIGH);
        if (notificationLargeIcon != -1)
            notificationBuilder.setLargeIcon(
                    BitmapFactory.decodeResource(currentAct.getResources(), notificationLargeIcon));

        notifManager.notify(0 /* ID of notification */, notificationBuilder.build());
    } catch (Exception e) {
        Log.w(TAG, "Failed to handle push notification", e);
    }
}

From source file:com.sxt.chat.utils.NotificationHelper.java

/**
 * ?? NotificationCompat.Builder/* w w  w.  j  av a2 s.co  m*/
 */
private NotificationCompat.Builder getNotificationBuilderByChannel(String... channel) {
    NotificationCompat.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        builder = new NotificationCompat.Builder(getApplicationContext(),
                channel == null || channel.length == 0 ? DEFAULT_CHANNEL : channel[0]);
    } else {
        builder = new NotificationCompat.Builder(this).setSound(soundUri);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//8.0 && 7.0? 
            builder.setPriority(NotificationManager.IMPORTANCE_HIGH);
        } else {
            builder.setPriority(NotificationCompat.PRIORITY_HIGH);
        }
    }
    return builder;
}

From source file:com.commonsware.android.notify.channel.MainActivity.java

private void initBattleChannel() {
    NotificationChannel channel = new NotificationChannel(CHANNEL_BATTLE,
            getString(R.string.channel_name_battle), NotificationManager.IMPORTANCE_HIGH);

    channel.setGroup(GROUP_UPDATES);//w  w  w  .j  a v a 2  s . co m
    channel.setShowBadge(true);
    mgr.createNotificationChannel(channel);
}

From source file:com.giovanniterlingen.windesheim.controllers.NotificationController.java

public void initNotificationChannels() {
    if (android.os.Build.VERSION.SDK_INT >= 26) {
        NotificationChannel pushChannel = new NotificationChannel(PUSH_NOTIFICATION_CHANNEL,
                ApplicationLoader.applicationContext.getResources().getString(R.string.push_notification),
                NotificationManager.IMPORTANCE_HIGH);

        pushChannel.setDescription(ApplicationLoader.applicationContext.getResources()
                .getString(R.string.push_notification_description));
        pushChannel.enableLights(true);/*  w w  w .  ja  va 2  s  .com*/
        pushChannel.enableVibration(true);
        pushChannel.setShowBadge(true);
        pushChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

        NotificationChannel persistentChannel = new NotificationChannel(PERSISTENT_NOTIFICATION_CHANNEL,
                ApplicationLoader.applicationContext.getResources().getString(R.string.persistent_notification),
                NotificationManager.IMPORTANCE_MIN);

        persistentChannel.setDescription(ApplicationLoader.applicationContext.getResources()
                .getString(R.string.persistent_notification_description));
        persistentChannel.enableLights(false);
        persistentChannel.enableVibration(false);
        persistentChannel.setShowBadge(false);
        persistentChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

        NotificationChannel serviceChannel = new NotificationChannel(SERVICE_NOTIFICATION_CHANNEL,
                ApplicationLoader.applicationContext.getResources().getString(R.string.service_notification),
                NotificationManager.IMPORTANCE_MIN);

        serviceChannel.setDescription(ApplicationLoader.applicationContext.getResources()
                .getString(R.string.service_notification_description));
        serviceChannel.enableLights(false);
        serviceChannel.enableVibration(false);
        serviceChannel.setShowBadge(false);
        serviceChannel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);

        NotificationManager mManager = (NotificationManager) ApplicationLoader.applicationContext
                .getSystemService(Context.NOTIFICATION_SERVICE);

        mManager.createNotificationChannel(pushChannel);
        mManager.createNotificationChannel(persistentChannel);
        mManager.createNotificationChannel(serviceChannel);
    }
}