Example usage for android.app Notification PRIORITY_DEFAULT

List of usage examples for android.app Notification PRIORITY_DEFAULT

Introduction

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

Prototype

int PRIORITY_DEFAULT

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

Click Source Link

Document

Default notification #priority .

Usage

From source file:com.android.messaging.sms.SmsStorageStatusManager.java

/**
 * Post sms storage low notification/*from w  w  w .j  a  v a 2s  .c om*/
 */
private static void postStorageLowNotification() {
    final Context context = Factory.get().getApplicationContext();
    final Resources resources = context.getResources();
    final PendingIntent pendingIntent = UIIntents.get().getPendingIntentForLowStorageNotifications(context);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle(resources.getString(R.string.sms_storage_low_title))
            .setTicker(resources.getString(R.string.sms_storage_low_notification_ticker))
            .setSmallIcon(R.drawable.ic_failed_light).setPriority(Notification.PRIORITY_DEFAULT)
            .setOngoing(true) // Can't be swiped off
            .setAutoCancel(false) // Don't auto cancel
            .setContentIntent(pendingIntent);

    final NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(builder);
    bigTextStyle.bigText(resources.getString(R.string.sms_storage_low_text));
    final Notification notification = bigTextStyle.build();

    final NotificationManagerCompat notificationManager = NotificationManagerCompat
            .from(Factory.get().getApplicationContext());

    notificationManager.notify(getNotificationTag(), PendingIntentConstants.SMS_STORAGE_LOW_NOTIFICATION_ID,
            notification);
}

From source file:com.bobomee.android.common.util.NotificationUtil.java

/**
 * ??// www .jav  a 2s. c o  m
 */
public static NotificationCompat.Builder initBuilder(Context context) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setWhen(System.currentTimeMillis())// ?
            .setContentIntent(getDefalutIntent(context, 0)).setPriority(Notification.PRIORITY_DEFAULT)// 
            .setOngoing(false)// ture
    // ???,??(?)???,?(,??,)
    // .setNumber(number)//?
    // .setAutoCancel(true)//?????
    // .setDefaults(Notification.DEFAULT_VIBRATE)//requires VIBRATE permission
    // Notification.DEFAULT_ALL Notification.DEFAULT_SOUND 
    // ???????defaults.
    ;
    return mBuilder;
}

From source file:com.rks.musicx.services.NotificationHandler.java

public static void buildNotification(MusicXService musicXService, String what) {
    if (musicXService == null) {
        return;/*w ww .  j av  a2  s  .c  o  m*/
    }
    RemoteViews remoteViews = new RemoteViews(musicXService.getPackageName(), R.layout.widget);
    RemoteViews smallremoteView = new RemoteViews(musicXService.getPackageName(), R.layout.small_notification);

    Intent intent = new Intent(musicXService, PlayingActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendInt = PendingIntent.getActivity(musicXService, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(
            musicXService).setWhen(System.currentTimeMillis()).setCategory(Intent.CATEGORY_APP_MUSIC)
                    .setPriority(Notification.PRIORITY_DEFAULT).setShowWhen(false).setAutoCancel(true)
                    .setCustomBigContentView(remoteViews).setContent(smallremoteView)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    remoteViews.setOnClickPendingIntent(R.id.item_view, pendInt);
    smallremoteView.setOnClickPendingIntent(R.id.small_item_view, pendInt);
    remoteViews.setTextViewText(R.id.title, musicXService.getsongTitle());
    remoteViews.setTextViewText(R.id.artist, musicXService.getsongArtistName());
    smallremoteView.setTextViewText(R.id.small_title, musicXService.getsongTitle());
    smallremoteView.setTextViewText(R.id.small_artist, musicXService.getsongArtistName());
    FavHelper favHelper = new FavHelper(musicXService);
    if (favHelper.isFavorite(musicXService.getsongId())) {
        remoteViews.setImageViewResource(R.id.action_favorite, R.drawable.ic_action_favorite);
    } else {
        remoteViews.setImageViewResource(R.id.action_favorite, R.drawable.ic_action_favorite_outline);
    }
    if (musicXService.isPlaying()) {
        builder.setSmallIcon(R.drawable.aw_ic_play);
        builder.setOngoing(true);
    } else {
        builder.setSmallIcon(R.drawable.aw_ic_pause);
        builder.setOngoing(false);
    }
    if (what.equals(PLAYSTATE_CHANGED)) {
        if (MediaPlayerSingleton.getInstance().getMediaPlayer().isPlaying()) {
            remoteViews.setImageViewResource(R.id.toggle, R.drawable.aw_ic_play);
            smallremoteView.setImageViewResource(R.id.small_toggle, R.drawable.aw_ic_play);
        } else {
            remoteViews.setImageViewResource(R.id.toggle, R.drawable.aw_ic_pause);
            smallremoteView.setImageViewResource(R.id.small_toggle, R.drawable.aw_ic_pause);
        }
    }
    handler.post(new Runnable() {
        @Override
        public void run() {
            ArtworkUtils.ArtworkLoader(musicXService, 300, 300, musicXService.getsongAlbumName(),
                    musicXService.getsongAlbumID(), new palette() {
                        @Override
                        public void palettework(Palette palette) {
                            int colors[] = Helper.getAvailableColor(musicXService, palette);
                            remoteViews.setInt(R.id.item_view, "setBackgroundColor", colors[0]);
                            remoteViews.setInt(R.id.title, "setTextColor", Color.WHITE);
                            remoteViews.setInt(R.id.artist, "setTextColor", Color.WHITE);
                            smallremoteView.setInt(R.id.small_item_view, "setBackgroundColor", colors[0]);
                            smallremoteView.setInt(R.id.small_title, "setTextColor", Color.WHITE);
                            smallremoteView.setInt(R.id.small_artist, "setTextColor", Color.WHITE);
                        }
                    }, new bitmap() {
                        @Override
                        public void bitmapwork(Bitmap bitmap) {
                            remoteViews.setImageViewBitmap(R.id.artwork, bitmap);
                            smallremoteView.setImageViewBitmap(R.id.small_artwork, bitmap);
                            NotificationManagerCompat.from(musicXService).notify(notificationID,
                                    builder.build());
                        }

                        @Override
                        public void bitmapfailed(Bitmap bitmap) {
                            remoteViews.setImageViewBitmap(R.id.artwork, bitmap);
                            smallremoteView.setImageViewBitmap(R.id.small_artwork, bitmap);
                            NotificationManagerCompat.from(musicXService).notify(notificationID,
                                    builder.build());
                        }
                    });
        }
    });
    controls(remoteViews, smallremoteView, musicXService);
}

From source file:org.androidpn.client.Notifier.java

public void notify(String notificationId, String apiKey, String title, String message, String uri,
        String imageUrl) {//  ww w  .  j  ava2s. c o  m
    Log.d(LOGTAG, "notify()...");

    Log.d(LOGTAG, "notificationId=" + notificationId);
    Log.d(LOGTAG, "notificationApiKey=" + apiKey);
    Log.d(LOGTAG, "notificationTitle=" + title);
    Log.d(LOGTAG, "notificationMessage=" + message);
    Log.d(LOGTAG, "notificationUri=" + uri);

    if (isNotificationEnabled()) {
        // Show the toast
        if (isNotificationToastEnabled()) {
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();
        }
        mBuilder.setWhen(System.currentTimeMillis())//?
                .setPriority(Notification.PRIORITY_DEFAULT)//
                //            .setAutoCancel(true)//?????
                .setOngoing(false)//ture???,??(?)???,?(,??,)
                .setDefaults(Notification.DEFAULT_VIBRATE)//???????defaults??
                //Notification.DEFAULT_ALL  Notification.DEFAULT_SOUND  // requires VIBRATE permission
                .setSmallIcon(getNotificationIcon());

        mBuilder.setAutoCancel(true)//?
                .setContentTitle(title).setContentText(message).setTicker(message);
        // Notification
        if (isNotificationSoundEnabled()) {
            mBuilder.setDefaults(Notification.DEFAULT_SOUND);
        }
        if (isNotificationVibrateEnabled()) {
            mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
        }
        mBuilder.setOnlyAlertOnce(true);

        //            Intent intent;
        //            if (uri != null
        //                    && uri.length() > 0
        //                    && (uri.startsWith("http:") || uri.startsWith("https:")
        //                            || uri.startsWith("tel:") || uri.startsWith("geo:"))) {
        //                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        //            } else {
        //                String callbackActivityPackageName = sharedPrefs.getString(
        //                        Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, "");
        //                String callbackActivityClassName = sharedPrefs.getString(
        //                        Constants.CALLBACK_ACTIVITY_CLASS_NAME, "");
        //                intent = new Intent().setClassName(callbackActivityPackageName,
        //                        callbackActivityClassName);
        //                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            }

        Intent intent = new Intent(context, NotificationDetailsActivity.class);
        intent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        intent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
        intent.putExtra(Constants.NOTIFICATION_TITLE, title);
        intent.putExtra(Constants.NOTIFICATION_MESSAGE, message);
        intent.putExtra(Constants.NOTIFICATION_URI, uri);
        intent.putExtra(Constants.NOTIFICATION_IMAGE_URL, imageUrl);

        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent contentIntent = PendingIntent.getActivity(context, random.nextInt(), intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(contentIntent);
        notificationManager.notify(random.nextInt(), mBuilder.build());

    } else {
        Log.w(LOGTAG, "Notificaitons disabled.");
    }
}

From source file:com.alibaba.weex.update.UpdateService.java

private void handleActionUpdate(String url) {
    manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    builder = new NotificationCompat.Builder(this);
    builder.setContentTitle(CheckForUpdateUtil.getStringRes(R.string.update_downloading))
            .setContentText(CheckForUpdateUtil.getStringRes(R.string.update_progress) + " 0%")
            .setTicker(CheckForUpdateUtil.getStringRes(R.string.update_downloading))
            .setWhen(System.currentTimeMillis()).setPriority(Notification.PRIORITY_DEFAULT)
            .setSmallIcon(R.mipmap.ic_launcher).setProgress(100, 0, false);
    manager.notify(NOTIFY_ID, builder.build());

    WXLogUtils.e("Update", "start download");
    Downloader.download(url,/*from w w w.  j a  va2 s. c o m*/
            new Downloader.DownloadCallback(getCacheDir().getAbsolutePath(), "playground.apk") {

                @Override
                public void onProgress(float progress) {
                    if (progress * 100 - progress >= 1) {
                        int p = (int) (progress * 100);
                        builder.setContentText(
                                CheckForUpdateUtil.getStringRes(R.string.update_progress) + p + "%");
                        builder.setProgress(100, p, false);
                        manager.notify(NOTIFY_ID, builder.build());
                        WXLogUtils.d("Update", "progress:" + p);
                    }
                }

                @Override
                public void onResponse(File file) {
                    WXLogUtils.d("Update", "success: " + file.getAbsolutePath());
                    manager.cancel(NOTIFY_ID);
                    Uri uri = Uri.fromFile(file);
                    Intent installIntent = new Intent(Intent.ACTION_VIEW);

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                        installIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        Uri contentUri = FileProvider.getUriForFile(WXEnvironment.getApplication(),
                                BuildConfig.APPLICATION_ID + ".fileprovider", file);
                        installIntent.setDataAndType(contentUri, "application/vnd.android.package-archive");
                    } else {
                        installIntent.setDataAndType(uri, "application/vnd.android.package-archive");
                        installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    }
                    startActivity(installIntent);
                }

                @Override
                public void onError(final Exception e) {
                    WXSDKManager.getInstance().getWXRenderManager().postOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(UpdateService.this, "Failed to update:" + e.getMessage(),
                                    Toast.LENGTH_SHORT).show();
                        }
                    }, 0);
                }
            });
}

From source file:com.guayaba.tapir.NotificationHelper.java

/**
 * Call this to build the {@link Notification}.
 *//*w  w  w.  ja  v  a2  s.  c  o  m*/
public void buildNotification(final String albumName, final String artistName, final String trackName,
        final Long albumId, final Bitmap albumArt, final boolean isPlaying) {

    // Default notfication layout
    mNotificationTemplate = new RemoteViews(mService.getPackageName(), R.layout.notification_template_base);

    // Set up the content view
    initCollapsedLayout(trackName, artistName, albumArt);

    // Notification Builder
    mNotification = new NotificationCompat.Builder(mService).setSmallIcon(R.drawable.stat_notify_music)
            .setContentIntent(getPendingIntent()).setPriority(Notification.PRIORITY_DEFAULT)
            .setContent(mNotificationTemplate).build();
    // Control playback from the notification
    initPlaybackActions(isPlaying);
    if (ApolloUtils.hasJellyBean()) {
        // Expanded notifiction style
        mExpandedView = new RemoteViews(mService.getPackageName(),
                R.layout.notification_template_expanded_base);
        mNotification.bigContentView = mExpandedView;
        // Control playback from the notification
        initExpandedPlaybackActions(isPlaying);
        // Set up the expanded content view
        initExpandedLayout(trackName, albumName, artistName, albumArt);
    }
    mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
}

From source file:com.gecq.musicwave.player.NotificationHelper.java

/**
 * Call this to build the {@link Notification}.
 *//*from w  ww .j  a  v a 2  s . c o m*/
@SuppressLint("NewApi")
public void buildNotification(final String albumName, final String artistName, final String trackName,
        final Long albumId, final Bitmap albumArt, final boolean isPlaying) {

    // Default notfication layout
    mNotificationTemplate = new RemoteViews(mService.getPackageName(), R.layout.notification_template_base);

    // Set up the content view
    initCollapsedLayout(trackName, artistName, albumArt);

    // Notification Builder
    mNotification = new NotificationCompat.Builder(mService).setSmallIcon(R.drawable.notification_icon)
            .setContentIntent(getPendingIntent()).setPriority(Notification.PRIORITY_DEFAULT)
            .setContent(mNotificationTemplate).build();
    // Control playback from the notification
    initPlaybackActions(isPlaying);
    if (CommonUtils.hasJellyBean()) {
        // Expanded notifiction style
        mExpandedView = new RemoteViews(mService.getPackageName(),
                R.layout.notification_template_expanded_base);
        mNotification.bigContentView = mExpandedView;
        // Control playback from the notification
        initExpandedPlaybackActions(isPlaying);
        // Set up the expanded content view
        initExpandedLayout(trackName, albumName, artistName, albumArt);
    }
    mService.startForeground(MUSIC_WAVE_SERVICE, mNotification);
}

From source file:com.spollo.player.NotificationHelper.java

/**
 * Call this to build the {@link Notification}.
 */// w w w  .j  a  va 2s.c om
public void buildNotification(final String albumName, final String artistName, final String trackName,
        final Long albumId, final Bitmap albumArt, final boolean isPlaying) {

    // Default notfication layout
    mNotificationTemplate = new RemoteViews(mService.getPackageName(), R.layout.notification_template_base);

    // Set up the content view
    initCollapsedLayout(trackName, artistName, albumArt);

    // Notification Builder
    mNotification = new NotificationCompat.Builder(mService).setSmallIcon(R.drawable.stat_notify_music)
            .setContentIntent(getPendingIntent()).setPriority(Notification.PRIORITY_DEFAULT)
            .setContent(mNotificationTemplate).build();
    // Control playback from the notification
    initPlaybackActions(isPlaying);
    if (ApolloUtils.hasJellyBean()) {
        // Expanded notifiction style
        mExpandedView = new RemoteViews(mService.getPackageName(),
                R.layout.notification_template_expanded_base);
        mNotification.bigContentView = mExpandedView;
        // Control playback from the notification
        initExpandedPlaybackActions(isPlaying);
        // Set up the expanded content view
        initExpandedLayout(trackName, albumName, artistName, albumArt);
    }
    mService.startForeground(SPOLLO_MUSIC_SERVICE, mNotification);
}

From source file:com.andrew.apollo.NotificationHelper.java

/**
 * Call this to build the {@link Notification}.
 *//*w  ww .ja v  a 2s . c  o m*/
public void buildNotification(final String albumName, final String artistName, final String trackName,
        final Long albumId, final Bitmap albumArt) {

    // Default notfication layout
    mNotificationTemplate = new RemoteViews(mService.getPackageName(), R.layout.notification_template_base);

    // Set up the content view
    initCollapsedLayout(trackName, artistName, albumArt);

    if (ApolloUtils.hasHoneycomb()) {
        // Notification Builder
        mNotification = new NotificationCompat.Builder(mService).setSmallIcon(R.drawable.stat_notify_music)
                .setContentIntent(getPendingIntent()).setPriority(Notification.PRIORITY_DEFAULT)
                .setContent(mNotificationTemplate).build();
        // Control playback from the notification
        initPlaybackActions();
        if (ApolloUtils.hasJellyBean()) {
            // Expanded notifiction style
            mExpandedView = new RemoteViews(mService.getPackageName(),
                    R.layout.notification_template_expanded_base);
            mNotification.bigContentView = mExpandedView;
            // Control playback from the notification
            initExpandedPlaybackActions();
            // Set up the expanded content view
            initExpandedLayout(trackName, albumName, artistName, albumArt);
        }
        mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
    } else {
        // FIXME: I do not understand why this happens, but the
        // NotificationCompat
        // API does not work on Gingerbread. Specifically, {@code
        // #mBuilder.setContent()} won't apply the custom RV in Gingerbread.
        // So,
        // until this is fixed I'll just use the old way.
        mNotification = new Notification();
        mNotification.contentView = mNotificationTemplate;
        mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
        mNotification.icon = R.drawable.stat_notify_music;
        mNotification.contentIntent = getPendingIntent();
        mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
    }
}

From source file:com.boko.vimusic.NotificationHelper.java

/**
 * Call this to build the {@link Notification}.
 *///w  ww  . j av  a 2s .co m
public void buildNotification(final String albumName, final String artistName, final String trackName,
        final String albumId, final Bitmap albumArt, final boolean isPlaying) {
    // Default notfication layout
    mNotificationTemplate = new RemoteViews(mService.getPackageName(), R.layout.notification_template_base);

    // Set up the content view
    initCollapsedLayout(trackName, artistName, albumArt);

    // Notification Builder
    mNotification = new NotificationCompat.Builder(mService).setSmallIcon(R.drawable.stat_notify_music)
            .setContentIntent(getPendingIntent()).setPriority(Notification.PRIORITY_DEFAULT)
            .setContent(mNotificationTemplate).build();
    // Control playback from the notification
    initPlaybackActions(isPlaying);
    if (CommonUtils.hasJellyBean()) {
        // Expanded notifiction style
        mExpandedView = new RemoteViews(mService.getPackageName(),
                R.layout.notification_template_expanded_base);
        mNotification.bigContentView = mExpandedView;
        // Control playback from the notification
        initExpandedPlaybackActions(isPlaying);
        // Set up the expanded content view
        initExpandedLayout(trackName, albumName, artistName, albumArt);
    }
    mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
}