android.support.v7.app.NotificationCompat Java Examples

The following examples show how to use android.support.v7.app.NotificationCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MediaNotificationManager.java    From react-native-audio-streaming-player with MIT License 6 votes vote down vote up
private void setNotificationPlaybackState(NotificationCompat.Builder builder) {
    if (mPlaybackState == null || !mStarted) {
        mService.stopForeground(true);
        return;
    }

    if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING && mPlaybackState.getPosition() >= 0) {
        builder
            .setWhen(System.currentTimeMillis() - mPlaybackState.getPosition())
            .setShowWhen(true)
            .setUsesChronometer(true);
    } else {
        builder
            .setWhen(0)
            .setShowWhen(false)
            .setUsesChronometer(false);
    }

    // Make sure that the notification can be dismissed by the user when we are not playing:
    builder.setOngoing(mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING);
}
 
Example #2
Source File: ElloGcmListenerService.java    From ello-android with MIT License 6 votes vote down vote up
private void sendNotification(String title, String body, String webUrl) {
    NotificationCompat.Builder builder =
            (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_stat_gcm)
                    .setContentTitle(title)
                    .setContentText(body);

    Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
    resultIntent.putExtra("web_url", webUrl);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_CANCEL_CURRENT
            );
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(NOTIFICATION_ID, builder.build());
}
 
Example #3
Source File: Notifications.java    From mpush-android with Apache License 2.0 6 votes vote down vote up
private Notification build(PendingIntent clickIntent, PendingIntent cancelIntent,
                           String ticker, String title, String content, int number) {
    return new NotificationCompat.Builder(context)
            .setSmallIcon(smallIcon)
            .setLargeIcon(largeIcon)
            .setContentTitle(title)
            .setContentText(content)
            .setTicker(ticker)
            .setContentIntent(clickIntent)
            .setDeleteIntent(cancelIntent)
            .setNumber(number)
            .setAutoCancel(true)
            .setOnlyAlertOnce(true)
                    //.setLights(0xff00ff00, 5000, 5000)
            .setDefaults(defaults)
            .build();
}
 
Example #4
Source File: DownloadService.java    From AndroidDemo with MIT License 6 votes vote down vote up
private void sendNotification(){

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.push));
        //禁止用户点击删除按钮删除
        builder.setAutoCancel(false);
        //禁止滑动删除
        builder.setOngoing(true);
        builder.setShowWhen(false);
        builder.setContentTitle("下载中..."+progress+"%");
        builder.setProgress(100,progress,false);
        //builder.setContentInfo(progress+"%");
        builder.setOngoing(true);
        builder.setShowWhen(false);
        Intent intent = new Intent(this,DownloadService.class);
        intent.putExtra("command",1);
        Notification notification = builder.build();
        manger.notify(MainActivity.TYPE_Progress,notification);

    }
 
Example #5
Source File: NotifyManager.java    From LLApp with Apache License 2.0 6 votes vote down vote up
/**
 * 折叠式
 *
 * @param context
 */
public static void shwoNotify(Context context,int flag) {
    //先设定RemoteViews
    RemoteViews view_custom = new RemoteViews(context.getPackageName(), R.layout.notification);
    //设置对应IMAGEVIEW的ID的资源图片
    view_custom.setImageViewResource(R.id.image, R.mipmap.ic_launcher);
    view_custom.setTextViewText(R.id.bbs_type_Title, "今日头条");
    view_custom.setTextColor(R.id.text, Color.BLACK);
    view_custom.setTextViewText(R.id.text, "金州勇士官方宣布球队已经解雇了主帅马克-杰克逊,随后宣布了最后的结果。");
    view_custom.setTextColor(R.id.bbs_type_Title, Color.BLACK);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setContent(view_custom)
            .setContentIntent(PendingIntent.getActivity(context, 4, new Intent(context, MainActivity.class), PendingIntent.FLAG_CANCEL_CURRENT))
            .setWhen(System.currentTimeMillis())// 通知产生的时间,会在通知信息里显示
            .setTicker("有新资讯")
            .setPriority(Notification.PRIORITY_HIGH)// 设置该通知优先级
            .setOngoing(false)//不是正在进行的   true为正在进行  效果和.flag一样
            .setSmallIcon(R.mipmap.ic_launcher);
    Notification notify = mBuilder.build();
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
    notificationManager.notify(flag, notify);
}
 
Example #6
Source File: NotifyManager.java    From LLApp with Apache License 2.0 6 votes vote down vote up
/**
 * 悬挂式,部分系统厂商不支持
 *
 * @param context
 */
public static void showFullScreen(Context context,int flag) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://blog.csdn.net/linglongxin24"));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, mIntent, 0);
    builder.setContentIntent(pendingIntent);
    builder.setSmallIcon(R.mipmap.ic_launcher);
    builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));
    builder.setAutoCancel(true);
    builder.setContentTitle("悬挂式通知");
    //设置点击跳转
    Intent hangIntent = new Intent();
    hangIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    hangIntent.setClass(context, NotifyActivity.class);
    //如果描述的PendingIntent已经存在,则在产生新的Intent之前会先取消掉当前的
    PendingIntent hangPendingIntent = PendingIntent.getActivity(context, 0, hangIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setFullScreenIntent(hangPendingIntent, true);
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
    notificationManager.notify(flag, builder.build());
}
 
Example #7
Source File: MediaNotificationManager.java    From LyricHere with Apache License 2.0 6 votes vote down vote up
private void fetchBitmapFromURLAsync(final String bitmapUrl,
                                     final NotificationCompat.Builder builder) {
    AlbumArtCache.getInstance().fetch(bitmapUrl, new AlbumArtCache.FetchListener() {
        @Override
        public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) {
            if (mMetadata != null && mMetadata.getDescription() != null &&
                    artUrl.equals(mMetadata.getDescription().getIconUri().toString())) {
                // If the media is still the same, update the notification:
                LogUtils.d(TAG, "fetchBitmapFromURLAsync: set bitmap to ", artUrl);
                if (bitmap != null && !bitmap.isRecycled()) {
                    builder.setLargeIcon(bitmap);
                }
                mNotificationManager.notify(NOTIFICATION_ID, builder.build());
            }
        }
    });
}
 
Example #8
Source File: ActivityRecognizedService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static void disableMotionTrackingDueToErrors(Context context) {
    final long requested = getInternalPrefsLong(REQUESTED);
    final long received = getInternalPrefsLong(RECEIVED);
    Home.toaststaticnext("DISABLED MOTION TRACKING DUE TO FAILURES! See Error Log!");
    final String msg = "Had to disable motion tracking feature as it did not seem to be working and may be incompatible with your phone. Please report this to the developers using the send logs feature: " + requested + " vs " + received + " " + JoH.getDeviceDetails();
    UserError.Log.wtf(TAG, msg);
    UserError.Log.ueh(TAG, msg);
    Pref.setBoolean("motion_tracking_enabled", false);
    evaluateRequestReceivedCounters(true, context); // mark for disable
    setInternalPrefsLong(REQUESTED, 0);
    setInternalPrefsLong(RECEIVED, 0);
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    Intent intent = new Intent(xdrip.getAppContext(), ErrorsActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(xdrip.getAppContext(), 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);
    builder.setContentText("Shut down motion detection! See Error Logs - Please report to developer" + JoH.dateTimeText(JoH.tsl()));
    builder.setContentIntent(pendingIntent);
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setContentTitle("Problem with motion detection!");
    NotificationManagerCompat.from(context).notify(VEHICLE_NOTIFICATION_ERROR_ID, builder.build());
}
 
Example #9
Source File: BigPicBuilder.java    From NotifyUtil with Apache License 2.0 6 votes vote down vote up
@Override
public void build() {
    super.build();
    NotificationCompat.BigPictureStyle picStyle = new NotificationCompat.BigPictureStyle();
    if(bitmap==null || bitmap.isRecycled()){
        if(bigPic >0){
            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inScaled = true;
            options.inSampleSize = 2;
            bitmap = BitmapFactory.decodeResource(NotifyUtil.context.getResources(),
                    bigPic, options);
        }
    }
    picStyle.bigPicture(bitmap);
    //picStyle.bigLargeIcon(bitmap);
    picStyle.setBigContentTitle(contentTitle);
    picStyle.setSummaryText(summaryText);
    cBuilder.setStyle(picStyle);
}
 
Example #10
Source File: NotificationUtil.java    From Prodigal with Apache License 2.0 6 votes vote down vote up
public void showPlayingNotification(PlayerService service, MediaSessionCompat session) {
    NotificationCompat.Builder builder = notificationBuilder(service, session);
    if( builder == null ) {
        return;
    }
    NotificationCompat.Action action;
    if (session.isActive()) {
        action = new NotificationCompat.Action(android.R.drawable.ic_media_pause, "Pause", playIntent);
    } else {
        action = new NotificationCompat.Action(android.R.drawable.ic_media_play, "Play", pauseIntent);
    }
    builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_previous, "Previous",
            prevIntent));
    builder.addAction(action);
    builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_next, "Next",
            nextIntent));

    builder.setOngoing(true);

    builder.setStyle(new NotificationCompat.MediaStyle().setShowActionsInCompactView(1).setMediaSession(session.getSessionToken()));
    builder.setSmallIcon(R.mipmap.ic_launcher);
    NotificationManagerCompat.from(service).notify(NOTIFICATION_ID, builder.build());
}
 
Example #11
Source File: NotificationUtil.java    From Prodigal with Apache License 2.0 6 votes vote down vote up
private NotificationCompat.Builder notificationBuilder(PlayerService context, MediaSessionCompat session) {
    MediaControllerCompat controller = session.getController();
    MediaMetadataCompat mediaMetadata = controller.getMetadata();
    MediaDescriptionCompat description = mediaMetadata.getDescription();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder
            .setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setSubText(description.getDescription())
            .setLargeIcon(mediaMetadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ART))
            .setContentIntent(clickIntent)
            .setDeleteIntent(
                    MediaButtonReceiver.buildMediaButtonPendingIntent(context, receiverName, PlaybackStateCompat.ACTION_STOP))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    return builder;
}
 
Example #12
Source File: NotifyUtil0.java    From NotifyUtil with Apache License 2.0 6 votes vote down vote up
/**
 * 容纳大图片的通知
 *
 * @param pendingIntent
 * @param smallIcon
 * @param ticker
 * @param title
 * @param bigPic
 */
public void notify_bigPic(PendingIntent pendingIntent, int smallIcon, String ticker,
                          String title, String content, int bigPic, boolean sound, boolean vibrate, boolean lights) {

    setCompatBuilder(pendingIntent, smallIcon, ticker, title, null, sound, vibrate, lights);
    NotificationCompat.BigPictureStyle picStyle = new NotificationCompat.BigPictureStyle();
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = true;
    options.inSampleSize = 2;
    Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(),
            bigPic, options);
    picStyle.bigPicture(bitmap);
    picStyle.bigLargeIcon(bitmap);
    cBuilder.setContentText(content);
    cBuilder.setStyle(picStyle);
    sent();
}
 
Example #13
Source File: UsbBroadcastReceiver.java    From USB_Mass_Storage_Enabler with MIT License 5 votes vote down vote up
public static void showNotification(Context context) {

        if(data==null) data = context.getSharedPreferences(Constants.MyPREFERENCES, Context.MODE_PRIVATE);

        if(data.getBoolean(Constants.NotifsEnable, true) || data.getBoolean(Constants.autoStart, false)&&!MainActivity.isAppOpen) {
            PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
            PendingIntent ums_action;
            if(isUMSdisabled) {
                ums_action = PendingIntent.getBroadcast(context, 0, new Intent(intentEnableUMS), PendingIntent.FLAG_CANCEL_CURRENT);
            } else {
                Intent i = new Intent(intentDisableUMS);
                i.putExtra("removeNotif", false);
                ums_action = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
            }

            NotificationManager notificationManager  = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
            Notification notification = new NotificationCompat.Builder(context)
                    .setTicker(isUMSdisabled ? context.getString(R.string.notif_ums_disabled) : context.getString(R.string.notif_ums_enabled))
                    .setSmallIcon(android.R.drawable.stat_notify_sdcard_usb)
                    .setContentTitle(isUMSdisabled ? context.getString(R.string.notif_ums_disabled) : context.getString(R.string.notif_ums_enabled))
                    .setContentText(isUMSdisabled ? context.getString(R.string.notif_ums_disabled_msg):context.getString(R.string.notif_ums_enabled_msg))
                    .setContentIntent(pi)
                    //.setOngoing(true)
                    .addAction(new android.support.v4.app.NotificationCompat.Action.Builder(
                            R.drawable.empty_icon,
                            isUMSdisabled ? context.getString(R.string.action_enable_ums_short): context.getString(R.string.action_disable_ums_short),
                            ums_action
                    ).build())
                    .build();
            if(notification!=null) notificationManager.notify(0, notification);
        }
    }
 
Example #14
Source File: MediaNotificationManager.java    From delion with Apache License 2.0 5 votes vote down vote up
private void setMediaStyleNotificationText(NotificationCompat.Builder builder) {
    builder.setContentTitle(mMediaNotificationInfo.metadata.getTitle());
    String artistAndAlbumText = getArtistAndAlbumText(mMediaNotificationInfo.metadata);
    if (isRunningN() || !artistAndAlbumText.isEmpty()) {
        builder.setContentText(artistAndAlbumText);
        builder.setSubText(mMediaNotificationInfo.origin);
    } else {
        // Leaving ContentText empty looks bad, so move origin up to the ContentText.
        builder.setContentText(mMediaNotificationInfo.origin);
    }
}
 
Example #15
Source File: NotifyUtil.java    From NotifyUtil with Apache License 2.0 5 votes vote down vote up
public NotifyUtil(Context context, int ID) {
    this.NOTIFICATION_ID = ID;
    mContext = context;
    // 获取系统服务来初始化对象
    nm = (NotificationManager) mContext
            .getSystemService(Activity.NOTIFICATION_SERVICE);
    cBuilder = new NotificationCompat.Builder(mContext);
}
 
Example #16
Source File: MusicReceiver.java    From Lyrically with MIT License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

    Bundle extras = intent.getExtras();
    boolean isPlaying = extras.getBoolean(extras.containsKey("playstate") ? "playstate" : "playing", true);

    if (isPlaying) {
        // if the music is playing, send an intent to LyricsService
        Intent intent1 = new Intent(context, LyricsService.class);
        intent1.putExtra("artist", intent.getStringExtra("artist"));
        intent1.putExtra("track", intent.getStringExtra("track"));
        context.startService(intent1);
    } else { // make the notification dismissible
        NotificationManager mNotifyManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
        Intent stopIntent = new Intent(context, StopService.class);
        mBuilder.setContentTitle("Lyrically")
                .setDeleteIntent(PendingIntent.getService(context, 0, stopIntent, 0)) // stop LyricsService when user swipes away the notification
                .setOngoing(false)
                .setPriority(Notification.PRIORITY_MIN)
                .setSmallIcon(R.mipmap.ic_launcher);
        mNotifyManager.notify(
                26181317,
                mBuilder.build());
    }

}
 
Example #17
Source File: OfflineNotifier.java    From TLint with Apache License 2.0 5 votes vote down vote up
public void notifyPictureSuccess(int picSize, long picLength) {
    String title = "图片离线完成";
    String content = String.format("%s张图片,节省流量%s", String.valueOf(picSize),
            FormatUtil.formatFileSize(picLength));

    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);

    builder.setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setAutoCancel(true)
            .setContentText(content);

    OfflineNotifier.this.notify(OfflinePicture, 0, builder);
}
 
Example #18
Source File: NotifyManager.java    From LLApp with Apache License 2.0 5 votes vote down vote up
/**
 * 显示一个简单通知
 * @param context
 */
public static void showSimpleNotify(Context context,int flag){
    Notification notification = new NotificationCompat.Builder(context)
            /**设置通知左边的大图标**/
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
            /**设置通知右边的小图标**/
            .setSmallIcon(R.mipmap.ic_launcher)
            /**通知首次出现在通知栏,带上升动画效果的**/
            .setTicker("通知来了")
            /**设置通知的标题**/
            .setContentTitle("这是一个通知的标题")
            /**设置通知的内容**/
            .setContentText("这是一个通知的内容这是一个通知的内容")
            /**通知产生的时间,会在通知信息里显示**/
            .setWhen(System.currentTimeMillis())
            /**设置该通知优先级**/
            .setPriority(Notification.PRIORITY_DEFAULT)
            /**设置这个标志当用户单击面板就可以让通知将自动取消**/
            .setAutoCancel(true)
            /**设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接)**/
            .setOngoing(false)
            /**向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:**/
            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
            .setContentIntent(PendingIntent.getActivity(context, 1, new Intent(context, NotifyActivity.class), PendingIntent.FLAG_CANCEL_CURRENT))
            .build();
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
    /**发起通知**/
    notificationManager.notify(flag, notification);
}
 
Example #19
Source File: NotifyUtil.java    From NotifyUtil with Apache License 2.0 5 votes vote down vote up
/**
 * 进行多项设置的通知(在小米上似乎不能设置大图标,系统默认大图标为应用图标)
 *
 * @param pendingIntent
 * @param smallIcon
 * @param ticker
 * @param title
 * @param content
 */
public void notify_mailbox(PendingIntent pendingIntent, int smallIcon, int largeIcon, ArrayList<String> messageList,
                           String ticker, String title, String content, boolean sound, boolean vibrate, boolean lights) {

    setCompatBuilder(pendingIntent, smallIcon, ticker, title, content, sound, vibrate, lights);

    // 将Ongoing设为true 那么notification将不能滑动删除
    //cBuilder.setOngoing(true);

    /**
     // 删除时
     Intent deleteIntent = new Intent(mContext, DeleteService.class);
     int deleteCode = (int) SystemClock.uptimeMillis();
     // 删除时开启一个服务
     PendingIntent deletePendingIntent = PendingIntent.getService(mContext,
     deleteCode, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT);
     cBuilder.setDeleteIntent(deletePendingIntent);

     **/

    Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), largeIcon);
    cBuilder.setLargeIcon(bitmap);

    cBuilder.setDefaults(Notification.DEFAULT_ALL);// 设置使用默认的声音
    //cBuilder.setVibrate(new long[]{0, 100, 200, 300});// 设置自定义的振动
    cBuilder.setAutoCancel(true);
    // builder.setSound(Uri.parse("file:///sdcard/click.mp3"));

    // 设置通知样式为收件箱样式,在通知中心中两指往外拉动,就能出线更多内容,但是很少见
    //cBuilder.setNumber(messageList.size());
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    for (String msg : messageList) {
        inboxStyle.addLine(msg);
    }
    inboxStyle.setSummaryText("[" + messageList.size() + "条]" + title);
    cBuilder.setStyle(inboxStyle);
    sent();
}
 
Example #20
Source File: MediaNotificationManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
@Nullable
static NotificationCompat.Builder getNotificationBuilderForTesting(
        int notificationId) {
    MediaNotificationManager manager = getManager(notificationId);
    if (manager == null) return null;

    return manager.mNotificationBuilder;
}
 
Example #21
Source File: TickService.java    From Tick with MIT License 5 votes vote down vote up
private NotificationCompat.Builder getNotification(String title, String text) {
    Intent intent = MainActivity.newIntent(getApplicationContext());

    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.ic_stat_notify);
    builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),
            R.mipmap.ic_logo));
    builder.setContentIntent(pi);
    builder.setContentTitle(title);
    builder.setContentText(text);

    return builder;
}
 
Example #22
Source File: NotificationUtil.java    From Prodigal with Apache License 2.0 5 votes vote down vote up
private NotificationUtil(Context context){
    appContext = context;
    notificationManager = (NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE);
    init();

    builder = new NotificationCompat.Builder(appContext);
    builder.setCustomBigContentView(bigView)
            .setCustomContentView(normalView)
            .setSmallIcon(R.drawable.pod_notification)
            .setContentIntent(clickIntent);
    notification = builder.build();
    notification.flags = Notification.FLAG_ONGOING_EVENT;
    receiverName = new ComponentName(context.getApplicationContext(), MediaButtonReceiver.class);
}
 
Example #23
Source File: OfflineNotifier.java    From TLint with Apache License 2.0 5 votes vote down vote up
public void notifyThreadsSuccess(int forumSize, int threadsSize, long threadsLength) {
    String title = String.format("%d个板块完成", forumSize);
    String content =
            String.format("共%d篇帖子,节省流量%s", threadsSize, FormatUtil.formatFileSize(threadsLength));

    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);

    builder.setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setAutoCancel(true)
            .setContentText(content);

    notify(OfflineThreads, 0, builder);
}
 
Example #24
Source File: UpdateAgent.java    From update with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    if (mBuilder == null) {
        String title = "下载中 - " + mContext.getString(mContext.getApplicationInfo().labelRes);
        mBuilder = new NotificationCompat.Builder(mContext);
        mBuilder.setOngoing(true)
                .setAutoCancel(false)
                .setPriority(Notification.PRIORITY_MAX)
                .setDefaults(Notification.DEFAULT_VIBRATE)
                .setSmallIcon(mContext.getApplicationInfo().icon)
                .setTicker(title)
                .setContentTitle(title);
    }
    onProgress(0);
}
 
Example #25
Source File: GoogleDriveService.java    From WheelLogAndroid with GNU General Public License v3.0 5 votes vote down vote up
private Notification buildNotification(String text, boolean complete) {
    int icon = complete ? R.drawable.ic_stat_cloud_done : R.drawable.ic_stat_cloud_upload;
    String contentText = file == null ? "" : file.getName();
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    return new NotificationCompat.Builder(this)
            .setSmallIcon(icon)
            .setContentTitle(text)
            .setContentText(contentText)
            .setContentIntent(pendingIntent)
            .build();
}
 
Example #26
Source File: TermService.java    From Ansole with GNU General Public License v2.0 5 votes vote down vote up
private Notification createNotification(PendingIntent pendingIntent) {
       NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
       builder.setOngoing(true);
       builder.setContentIntent(pendingIntent);
       builder.setSmallIcon(R.drawable.ic_stat_service_notification_icon);
       builder.setWhen(System.currentTimeMillis());
       builder.setTicker(getText(R.string.service_notify_text));
       builder.setContentTitle(getText(R.string.application_terminal));
       builder.setContentText(getText(R.string.service_notify_text));
       return builder.build();
}
 
Example #27
Source File: NetworkTasksService.java    From uPods-android with Apache License 2.0 5 votes vote down vote up
private void sendNewEpisodsNotification(final Podcast podcast) {
    StringBuilder titleStringBuilder = new StringBuilder();
    titleStringBuilder.append(podcast.getNewEpisodsCount());
    titleStringBuilder.append(" ");
    titleStringBuilder.append(podcast.getNewEpisodsCount() > 0 ? getString(R.string.new_episodes) : getString(R.string.new_episode));

    NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this);
    nBuilder.setContentTitle(podcast.getName());
    nBuilder.setContentInfo(podcast.getName());
    nBuilder.setContentText(titleStringBuilder.toString());
    nBuilder.setSmallIcon(R.mipmap.ic_launcher);

    try {
        Bitmap icon = null;
        if (podcast.getCoverImageUrl() != null) {
            URL url = new URL(podcast.getCoverImageUrl());
            icon = BitmapFactory.decodeStream(url.openConnection().getInputStream());
        } else {
            LetterBitmap letterBitmap = new LetterBitmap(this);
            icon = letterBitmap.getLetterTile(podcast.getName(), podcast.getName(), LARGE_ICON_SIZE, LARGE_ICON_SIZE);
        }
        nBuilder.setLargeIcon(icon);
    } catch (Exception e) {
        e.printStackTrace();
    }

    Intent intentOpen = new Intent(getApplicationContext(), ActivityMain.class);
    intentOpen.putExtra(ActivityPlayer.ACTIVITY_STARTED_FROM, NOTIFICATIONS_SHOW_PODCASTS_SUBSCRIBED);

    PendingIntent piOpen = PendingIntent.getActivity(this, 0, intentOpen, PendingIntent.FLAG_CANCEL_CURRENT);
    nBuilder.setContentIntent(piOpen);

    final Notification notification = nBuilder.build();
    NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nManager.notify(NEW_EPISODS_NOTIFICATION_ID, notification);
}
 
Example #28
Source File: MediaNotificationManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void setMediaStyleNotificationText(NotificationCompat.Builder builder) {
    builder.setContentTitle(mMediaNotificationInfo.metadata.getTitle());
    String artistAndAlbumText = getArtistAndAlbumText(mMediaNotificationInfo.metadata);
    if (isRunningN() || !artistAndAlbumText.isEmpty()) {
        builder.setContentText(artistAndAlbumText);
        builder.setSubText(mMediaNotificationInfo.origin);
    } else {
        // Leaving ContentText empty looks bad, so move origin up to the ContentText.
        builder.setContentText(mMediaNotificationInfo.origin);
    }
}
 
Example #29
Source File: Util.java    From Inspeckage with Apache License 2.0 5 votes vote down vote up
public static void showNotification(Context mContext, String info) {

        android.support.v4.app.NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(mContext)
                        .setSmallIcon(R.drawable.inspectorw)
                        .setContentTitle("Inspeckage")
                        .setContentText(info);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
        stackBuilder.addParentStack(MainActivity.class);
        NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(0, mBuilder.build());
    }
 
Example #30
Source File: MediaNotificationManager.java    From react-native-audio-streaming-player with MIT License 5 votes vote down vote up
private void addPlayPauseAction(NotificationCompat.Builder builder) {
    String label;
    int icon;
    PendingIntent intent;
    if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING) {
        label = "pause";
        icon = R.drawable.ic_pause_white_24dp;
        intent = mPauseIntent;
    } else {
        label = "play";
        icon = R.drawable.ic_play_arrow_white_24dp;
        intent = mPlayIntent;
    }
    builder.addAction(new NotificationCompat.Action(icon, label, intent));
}