Example usage for android.app Notification PRIORITY_MAX

List of usage examples for android.app Notification PRIORITY_MAX

Introduction

In this page you can find the example usage for android.app Notification PRIORITY_MAX.

Prototype

int PRIORITY_MAX

To view the source code for android.app Notification PRIORITY_MAX.

Click Source Link

Document

Highest #priority , for your application's most important items that require the user's prompt attention or input.

Usage

From source file:com.example.yongwoon.sendbirdtest.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from w  w  w  . j  a va2s. c  om*/
public static void sendNotification(Context context, String messageBody, String channelUrl) {
    Intent intent = MainActivity_.intent(context).get();
    intent.putExtra("groupChannelUrl", channelUrl);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 1 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher_round)
            .setContentTitle(context.getResources().getString(R.string.app_name)).setContentText(messageBody)
            .setAutoCancel(true).setSound(defaultSoundUri).setPriority(Notification.PRIORITY_MAX)
            .setDefaults(Notification.DEFAULT_ALL).setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:be.uhasselt.privacypolice.NotificationHandler.java

/**
 * Asks the user whether it is certain that a network should be currently available
 * @param SSID The name of the network//from  w  w  w  .  ja  v  a2 s .co m
 * @param BSSID The MAC address of the access point that triggered this (only used when we will block the AP)
 */
public void askNetworkPermission(String SSID, String BSSID) {
    Log.d("PrivacyPolice", "Asking permission for " + SSID + " (" + BSSID + ")");
    // Intent that will be used when the user allows the network
    Intent addIntent = new Intent(ctx, PermissionChangeReceiver.class);
    addIntent.putExtra("SSID", SSID).putExtra("BSSID", BSSID).putExtra("enable", true);
    PendingIntent addPendingIntent = PendingIntent.getBroadcast(ctx, 0, addIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    // Intent that will be used when the user blocks the network
    Intent disableIntent = new Intent(ctx, PermissionChangeReceiver.class);
    disableIntent.putExtra("SSID", SSID).putExtra("BSSID", BSSID).putExtra("enable", false);
    PendingIntent disablePendingIntent = PendingIntent.getBroadcast(ctx, 1, disableIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    // Intent that will be used when the user's OS does not support notification actions
    Intent activityIntent = new Intent(ctx, AskPermissionActivity.class);
    activityIntent.putExtra("SSID", SSID).putExtra("BSSID", BSSID);
    PendingIntent activityPendingIntent = PendingIntent.getActivity(ctx, 2, activityIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    // Build the notification dynamically, based on the network name
    Resources res = ctx.getResources();
    String headerString = String.format(res.getString(R.string.permission_header), SSID);
    String permissionString = String.format(res.getString(R.string.ask_permission), SSID);
    String yes = res.getString(R.string.yes);
    String no = res.getString(R.string.no);

    // NotificationCompat makes sure that the notification will also work on Android <4.0
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(R.drawable.ic_notification).setPriority(Notification.PRIORITY_MAX) // To force it to be first in list (and thus, expand)
            .setContentTitle(headerString).setContentText(permissionString)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(permissionString))
            .setContentIntent(activityPendingIntent)
            .addAction(android.R.drawable.ic_delete, no, disablePendingIntent)
            .addAction(android.R.drawable.ic_input_add, yes, addPendingIntent);
    notificationManager.notify(0, mBuilder.build());
}

From source file:kr.ds.myfoodpdx.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from  w w  w. j a  va 2s.  com*/
 */
private void sendNotification(String message) {

    boolean isvibrate = SharedPreference.getBooleanSharedPreference(getApplicationContext(), "isvibrate");

    Intent intent = new Intent(this, IntroActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder;
    if (isvibrate) {
        notificationBuilder = new NotificationCompat.Builder(this)
                .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.icon)
                .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
                .setPriority(Notification.PRIORITY_MAX).setContentIntent(pendingIntent);
    } else {
        notificationBuilder = new NotificationCompat.Builder(this)
                .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.icon)
                .setContentText(message).setAutoCancel(true).setVibrate(new long[] { 0 })
                .setPriority(Notification.PRIORITY_MAX).setContentIntent(pendingIntent);
    }

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

    notificationManager.notify(UniqueID.getRandomNumber(1000), notificationBuilder.build());
}

From source file:com.alucas.snorlax.module.feature.gym.EjectNotification.java

private Notification createNotification(final int pokemonNumber, final String pokemonName, final String gymName,
        final Double gymLatitude, final Double gymLongitude) {
    final Uri posURI = Uri.parse("geo:" + gymLatitude + "," + gymLongitude + "?q=" + gymLatitude + ","
            + gymLongitude + "(" + gymName + ")");
    final Intent posIntent = new Intent(Intent.ACTION_VIEW, posURI).setPackage("com.google.android.apps.maps");
    final PendingIntent posPendingIntent = PendingIntent.getActivity(mPokemonGoContext, 0, posIntent, 0);

    return new NotificationCompat.Builder(mSnorlaxContext)
            .setSmallIcon(// w  ww. java2 s . c om
                    R.drawable.ic_eject)
            .setLargeIcon(Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(mResources,
                            Resource.getPokemonResourceId(mSnorlaxContext, mResources, pokemonNumber)),
                    Resource.getLargeIconWidth(mResources), Resource.getLargeIconHeight(mResources), false))
            .setContentTitle(mSnorlaxContext.getString(R.string.notification_gym_eject_title, pokemonName))
            .setContentText(mSnorlaxContext.getString(R.string.notification_gym_eject_content, gymName))
            .setColor(ContextCompat.getColor(mSnorlaxContext, R.color.red_700)).setAutoCancel(true)
            .setContentIntent(posPendingIntent).setVibrate(new long[] { 0, 1000 })
            .setPriority(Notification.PRIORITY_MAX).setCategory(NotificationCompat.CATEGORY_ALARM).build();
}

From source file:com.belatrix.events.utils.fcm.EventsFirebaseMessagingService.java

private void sendNotification(String messageTitle, String messageBody) {
    Intent intent = MainActivity.makeIntent(this);
    intent.putExtra(MainActivity.PARAM_FROM_NOTIFICATION, true);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(messageTitle);
    bigTextStyle.bigText(messageBody);/*  w  w  w . jav a2s .  c o m*/

    Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher);

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

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.bx_connect_white).setLargeIcon(icon).setStyle(bigTextStyle)
            .setContentText(messageBody).setContentTitle(messageTitle).setAutoCancel(true)
            .setContentIntent(pendingIntent).setSound(alarmSound).setLights(0xFF8F0300, 1000, 200)
            .setPriority(Notification.PRIORITY_MAX);

    //for vibration
    Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(1000);

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

    long time = new Date().getTime();
    String tmpStr = String.valueOf(time);
    String last4Str = tmpStr.substring(tmpStr.length() - 5);
    int notificationId = Integer.valueOf(last4Str);

    notificationManager.notify(notificationId, notificationBuilder.build());
}

From source file:de.baumann.browser.helper.Activity_intent.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    onNewIntent(getIntent());//from w w  w.  j av  a 2 s .  c o  m
    android.content.Intent intent = getIntent();

    Uri data = intent.getData();

    String domain;
    if (Uri.parse(data.toString()).getHost().length() == 0) {
        domain = getString(R.string.app_domain);
    } else {
        domain = Uri.parse(data.toString()).getHost();
    }

    if (domain.contains("www.")) {
        domain = domain.replace("www.", "").toUpperCase();
    }

    String domain2 = domain.substring(0, 1).toUpperCase() + domain.substring(1);

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search, false);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit().putString("add_readLater_link", data.toString()).apply();
    sharedPref.edit().putString("add_readLater_domain", domain2).apply();

    Random rand = new Random();
    int n = rand.nextInt(100000);

    android.content.Intent iMain = new android.content.Intent();
    iMain.setData(data);
    iMain.setAction(Intent.ACTION_VIEW);
    iMain.setClassName(Activity_intent.this, "de.baumann.browser.Browser_left");

    android.content.Intent iAction = new android.content.Intent(this, Browser_left.class);
    iAction.setAction("readLater");

    android.content.Intent iAction_2 = new android.content.Intent(this, Activity_intent_add.class);
    iAction_2.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);

    PendingIntent piMain = PendingIntent.getActivity(this, n, iMain, 0);
    PendingIntent piAction = PendingIntent.getActivity(this, n, iAction, 0);
    PendingIntent piAction_2 = PendingIntent.getActivity(this, n, iAction_2, 0);

    NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.format_list_bulleted,
            getString(R.string.readLater_action), piAction).build();
    NotificationCompat.Action action_2 = new NotificationCompat.Action.Builder(R.drawable.format_list_bulleted,
            getString(R.string.readLater_action2), piAction_2).build();

    android.support.v4.app.NotificationCompat.Builder builderSummary = new android.support.v4.app.NotificationCompat.Builder(
            Activity_intent.this).setAutoCancel(true).setSmallIcon(R.drawable.earth)
                    .setColor(ContextCompat.getColor(Activity_intent.this, R.color.colorPrimary))
                    .setGroup("Browser").setGroupSummary(true).setContentIntent(piMain);

    Notification notification = new android.support.v4.app.NotificationCompat.Builder(Activity_intent.this)
            .setColor(ContextCompat.getColor(Activity_intent.this, R.color.colorPrimary))
            .setSmallIcon(R.drawable.earth).setContentTitle(getString(R.string.readLater_title))
            .setContentText(data.toString()).setContentIntent(piMain).setAutoCancel(true).setGroup("Browser")
            .addAction(action).addAction(action_2)
            .setStyle(new android.support.v4.app.NotificationCompat.BigTextStyle().bigText(data.toString()))
            .setPriority(Notification.PRIORITY_MAX).setVibrate(new long[0]).build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(n, notification);
    notificationManager.notify(0, builderSummary.build());

    finish();
}

From source file:com.icecream.snorlax.module.feature.encounter.EncounterNotification.java

@SuppressWarnings("deprecation")
void show(int pokemonNumber, String pokemonName, double iv, int attack, int defense, int stamina, int cp,
        double level, int hp, String move1, String move1Type, int move1Power, String move2, String move2Type,
        int move2Power, double pokeRate, double greatRate, double ultraRate, String type1, String type2,
        String pokemonClass) {//w ww  . j a v a  2 s  . co  m
    new Handler(Looper.getMainLooper()).post(() -> {

        Notification notification = new NotificationCompat.Builder(mContext)
                .setSmallIcon(R.drawable.ic_pokeball)
                .setLargeIcon(Bitmap.createScaledBitmap(
                        BitmapFactory.decodeResource(mResources, getPokemonResourceId(pokemonNumber)),
                        getLargeIconWidth(), getLargeIconHeight(), false))
                .setContentTitle(mContext.getString(R.string.notification_title, pokemonName, cp, level))
                .setContentText(mContext.getString(R.string.notification_content, iv, attack, defense, stamina))
                .setStyle(new NotificationCompat.InboxStyle()
                        .addLine(mContext.getString(R.string.notification_categoty_stats_content_iv, iv, attack,
                                defense, stamina))
                        .addLine(mContext.getString(R.string.notification_categoty_stats_content_hp, hp))
                        .addLine(getBoldSpannable(
                                mContext.getString(R.string.notification_categoty_moves_title)))
                        .addLine(mContext.getString(R.string.notification_categoty_moves_fast, move1, move1Type,
                                move1Power))
                        .addLine(mContext.getString(R.string.notification_categoty_moves_charge, move2,
                                move2Type, move2Power))
                        .addLine(getBoldSpannable(
                                mContext.getString(R.string.notification_categoty_catch_title)))
                        .addLine(mContext.getString(R.string.notification_categoty_catch_content, pokeRate,
                                greatRate, ultraRate))
                        .setSummaryText(getFooter(type1, type2, pokemonClass)))
                .setColor(ContextCompat.getColor(mContext, R.color.red_700)).setAutoCancel(true)
                .setVibrate(new long[] { 0 }).setPriority(Notification.PRIORITY_MAX)
                .setCategory(NotificationCompat.CATEGORY_ALARM).build();

        hideIcon(notification);

        mNotificationManager.notify(NOTIFICATION_ID, notification);
    });
}

From source file:org.messic.android.player.MessicPlayerNotification.java

private void createNotification() {
    if (this.notification != null) {
        return;/*from  w  w  w .  j av a  2s.  c om*/
    }

    mNotificationManager = (NotificationManager) this.service.getSystemService(Context.NOTIFICATION_SERVICE);
    RemoteViews contentView = new RemoteViews(this.service.getPackageName(),
            R.layout.bignotification_player_layout);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this.service)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("title")
            .setPriority(Notification.PRIORITY_MAX).setContent(contentView);

    Notification n = mBuilder.build();
    n.bigContentView = contentView;

    Intent intentClose = new Intent(ACTION_CLOSE);
    PendingIntent pintentClose = PendingIntent.getBroadcast(this.service, 0, intentClose, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivclose, pintentClose);
    Intent intentBack = new Intent(ACTION_BACK);
    PendingIntent pintentBack = PendingIntent.getBroadcast(this.service, 0, intentBack, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivback, pintentBack);
    Intent intentPlay = new Intent(ACTION_PLAY);
    PendingIntent pintentPlay = PendingIntent.getBroadcast(this.service, 0, intentPlay, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivplay, pintentPlay);
    Intent intentPause = new Intent(ACTION_PAUSE);
    PendingIntent pintentPause = PendingIntent.getBroadcast(this.service, 0, intentPause, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivpause, pintentPause);
    Intent intentNext = new Intent(ACTION_NEXT);
    PendingIntent pintentNext = PendingIntent.getBroadcast(this.service, 0, intentNext, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivnext, pintentNext);

    this.notification = n;
    this.service.startForeground(ONGOING_NOTIFICATION_ID, notification);
    this.registerBroadcastActions();
}

From source file:com.konsula.app.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./* ww w . j ava  2 s  . c om*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(MainActivity.togo, togo);
    intent.putExtra(MainActivity.bundle, bundle);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Konsula").setContentText(message)
            .setAutoCancel(true).setPriority(Notification.PRIORITY_MAX).setSound(defaultSoundUri)
            .setLights(0xff00ff00, 300, 100).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setVibrate(new long[] { 1000, 1000 }).setTicker("New messages from Konsula!")
            .setContentIntent(pendingIntent);

    //notificationBuilder.setOngoing(true);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

}

From source file:it.uniroma3.android.gpstracklogger.service.GPSLoggingService.java

private void showNotification() {
    Intent contentIntent = new Intent(this, GPSMainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addNextIntent(contentIntent);
    PendingIntent pending = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    String contentText = getString(R.string.running);
    long notificationTime = System.currentTimeMillis();

    if (Session.isLocationChanged()) {
        NumberFormat nf = new DecimalFormat("###.#####");
        Location last = Session.getCurrentLocation();
        contentText = "Lat" + ": " + nf.format(last.getLatitude()) + ", " + "Lon" + ": "
                + nf.format(last.getLongitude());

        notificationTime = Session.getCurrentLocation().getTime();
    }//from   w  w w.j  ava 2 s  . c  o m

    if (nfc == null) {
        nfc = new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.drawable.ic_gps_fixed_black_18dp).setPriority(Notification.PRIORITY_MAX)
                .setContentTitle(contentText).setOngoing(true).setContentIntent(pending);
    }

    nfc.setContentTitle(contentText);
    nfc.setContentText(getString(R.string.app_name));
    nfc.setWhen(notificationTime);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, nfc.build());
}