當前位置: 首頁>>代碼示例>>Java>>正文


Java NotificationCompat.Builder方法代碼示例

本文整理匯總了Java中android.support.v7.app.NotificationCompat.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java NotificationCompat.Builder方法的具體用法?Java NotificationCompat.Builder怎麽用?Java NotificationCompat.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.app.NotificationCompat的用法示例。


在下文中一共展示了NotificationCompat.Builder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onStartCommand

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(TAG, "WhiteService->onStartCommand");

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.mipmap.ic_launcher);
    builder.setContentTitle("Foreground");
    builder.setContentText("I am a foreground service");
    builder.setContentInfo("Content Info");
    builder.setWhen(System.currentTimeMillis());
    Intent activityIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
    Notification notification = builder.build();
    startForeground(FOREGROUND_ID, notification);
    return super.onStartCommand(intent, flags, startId);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:WhiteService.java

示例2: buildNotification

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private static Notification buildNotification(Context context, String title, String subject, String longText, String time, int icon, int color,
                                              PendingIntent contentIntent, PendingIntent deleteIntent) {

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle(title);
    builder.setContentText(subject);
    builder.setPriority(NotificationCompat.PRIORITY_MAX);
    builder.setStyle(new NotificationCompat.BigTextStyle(builder).bigText(longText));
    builder.setSmallIcon(icon);
    builder.setShowWhen(true);
    builder.setWhen(System.currentTimeMillis());
    builder.setContentIntent(contentIntent);
    builder.setSubText(time);
    builder.setAutoCancel(true);
    builder.setColor(color);

    return builder.build();

}
 
開發者ID:TonnyL,項目名稱:Espresso,代碼行數:20,代碼來源:ReminderService.java

示例3: createNotification

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private Notification createNotification(){
    if(mediaMetadata==null||playbackState==null) return null;
    NotificationCompat.Builder builder=new NotificationCompat.Builder(service);
    builder.setStyle(new  NotificationCompat.MediaStyle()
            .setMediaSession(token)
            .setShowActionsInCompactView(1))
            .setColor(Color.WHITE)
            .setPriority(Notification.PRIORITY_MAX)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setUsesChronometer(true)
            .setDeleteIntent(dismissedNotification(service))
            .setSmallIcon(R.drawable.ic_music_note)
            .setContentIntent(contentIntent(service))
            .setContentTitle(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST))
            .setContentText(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE))
            .addAction(prev(service));
    if(playbackState.getState()==PlaybackStateCompat.STATE_PLAYING){
        builder.addAction(pause(service));
    }else{
        builder.addAction(play(service));
    }
    builder.addAction(next(service));
    setNotificationPlaybackState(builder);
    loadImage(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI),builder);
    return builder.build();
}
 
開發者ID:vpaliyX,項目名稱:Melophile,代碼行數:27,代碼來源:TrackNotification.java

示例4: mainNotification

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private NotificationCompat.Builder mainNotification() {
    if (mainNotification == null) {
        mainNotification = new NotificationCompat.Builder(this);
        mainNotification.setAutoCancel(false);
        mainNotification.setSmallIcon(R.drawable.ic_play);

        // Close app on dismiss
        Intent intentDismiss = new Intent(this, NotificationDismissedReceiver.class);
        intentDismiss.putExtra("com.my.app.notificationId", notificationId);
        PendingIntent pendingDelete = PendingIntent.getBroadcast(this, notificationId, intentDismiss, 0);
        mainNotification.setDeleteIntent(pendingDelete);

        // Set focus to MainActivity
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        PendingIntent pendingContent = PendingIntent.getBroadcast(this, notificationId, intent, 0);
        mainNotification.setContentIntent(pendingContent);
    }
    return mainNotification;
}
 
開發者ID:sovteam,項目名稱:buddybox,代碼行數:21,代碼來源:MainActivity.java

示例5: setNotificationPlaybackState

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private void setNotificationPlaybackState(NotificationCompat.Builder builder) {
    if (playbackState == null || !isStarted) {
        return;
    }
    if (playbackState.getState() == PlaybackStateCompat.STATE_PLAYING
            && playbackState.getPosition() >= 0) {
        builder.setWhen(System.currentTimeMillis() - playbackState.getPosition())
                .setShowWhen(true)
                .setUsesChronometer(true);
    } else {
        builder.setWhen(0)
                .setShowWhen(false)
                .setUsesChronometer(false);
    }
    builder.setOngoing(playbackState.getState()==PlaybackStateCompat.STATE_PLAYING);
}
 
開發者ID:vpaliyX,項目名稱:Melophile,代碼行數:17,代碼來源:TrackNotification.java

示例6: sendGroupNoti

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
/**
 * 發送多個通知
 */
private void sendGroupNoti() {
    builder = new NotificationCompat.Builder(this);
    notification = builder.setContentTitle("恭喜您中獎了")
            .setContentIntent(pendingIntent)
            .setContentText("您有一條消息")
            .setTicker("新的消息來了!")
            .setWhen(System.currentTimeMillis())
            .setLargeIcon(bitmap)
            .setSmallIcon(R.mipmap.launcher512_qihoo)
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
            .build();

    for (int i=1; i<4; i++) {
        manager.notify(i, notification);
    }

}
 
開發者ID:BittleDragon,項目名稱:MyRepository,代碼行數:22,代碼來源:MainActivity.java

示例7: createNotification

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
/**
 * Creates the notification
 * 
 * @param messageResId
 *            message resource id. The message must have one String parameter,<br />
 *            f.e. <code>&lt;string name="name"&gt;%s is connected&lt;/string&gt;</code>
 * @param defaults
 *            signals that will be used to notify the user
 */
private void createNotification(final int messageResId, final int defaults) {
	final Intent parentIntent = new Intent(this, FeaturesActivity.class);
	parentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	final Intent targetIntent = new Intent(this, UARTActivity.class);

	final Intent disconnect = new Intent(ACTION_DISCONNECT);
	disconnect.putExtra(EXTRA_SOURCE, SOURCE_NOTIFICATION);
	final PendingIntent disconnectAction = PendingIntent.getBroadcast(this, DISCONNECT_REQ, disconnect, PendingIntent.FLAG_UPDATE_CURRENT);

	// both activities above have launchMode="singleTask" in the AndroidManifest.xml file, so if the task is already running, it will be resumed
	final PendingIntent pendingIntent = PendingIntent.getActivities(this, OPEN_ACTIVITY_REQ, new Intent[] { parentIntent, targetIntent }, PendingIntent.FLAG_UPDATE_CURRENT);
	final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
	builder.setContentIntent(pendingIntent);
	builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(messageResId, getDeviceName()));
	builder.setSmallIcon(R.drawable.ic_stat_notify_uart);
	builder.setShowWhen(defaults != 0).setDefaults(defaults).setAutoCancel(true).setOngoing(true);
	builder.addAction(new NotificationCompat.Action(R.drawable.ic_action_bluetooth, getString(R.string.uart_notification_action_disconnect), disconnectAction));

	final Notification notification = builder.build();
	final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
	nm.notify(NOTIFICATION_ID, notification);
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:32,代碼來源:UARTService.java

示例8: from

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
/**
 * Build a notification using the information from the given media session. Makes heavy use
 * of {@link MediaMetadataCompat#getDescription()} to extract the appropriate information.
 *
 * @param context      Context used to construct the notification.
 * @param mediaSession Media session to get information.
 * @return A pre-built notification with information from the given media session.
 */
static NotificationCompat.Builder from(
        Context context, MediaSessionCompat mediaSession) {
    MediaControllerCompat controller = mediaSession.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(description.getIconBitmap())
            .setContentIntent(controller.getSessionActivity())
            .setDeleteIntent(
                    MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    return builder;
}
 
開發者ID:SergeyVinyar,項目名稱:AndroidAudioExample,代碼行數:27,代碼來源:MediaStyleHelper.java

示例9: showNewPostNotifications

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
public static void showNewPostNotifications(){
    if (!Prefs.NotificationsEnabled()){
        return;
    }
    notificationPosts = PostRepository.getUnSeen();
    android.support.v4.app.NotificationCompat.InboxStyle inboxStyle = new android.support.v4.app.NotificationCompat.InboxStyle();
        for(Post post : notificationPosts){
            inboxStyle.addLine(post.getTitle());
        }
    //Notification sound
    SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(App.getAppContext());
    String strRingtonePreference = preference.getString("notifications_new_message_ringtone", "DEFAULT_SOUND");
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(App.getAppContext());
    mBuilder.setSmallIcon(R.drawable.ic_notifications)
            .setColor(App.getAppContext().getResources().getColor(R.color.brandColor))
            .setSound(Uri.parse(strRingtonePreference))
            .setAutoCancel(true)
            .setContentTitle("Laravel News")
            .setContentText(getSummaryMessage())
            .setContentIntent(getNotificationIntent())
            .setStyle(inboxStyle)
            .setGroup("LNA_NOTIFICATIONS_GROUP");

    //Check the vibrate
    if(Prefs.NotificationVibrateEnabled()){
        mBuilder.setVibrate(new long[]  {1000,1000});
    }

    Notification notification = mBuilder.build();
    // Issue the group notification
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(App.getAppContext());
    notificationManager.notify(1, notification);
}
 
開發者ID:jamesddube,項目名稱:LaravelNewsApp,代碼行數:35,代碼來源:Notify.java

示例10: getNotificationBuilderForTesting

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
@VisibleForTesting
@Nullable
static NotificationCompat.Builder getNotificationBuilderForTesting(
        int notificationId) {
    MediaNotificationManager manager = getManager(notificationId);
    if (manager == null) return null;

    return manager.mNotificationBuilder;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:10,代碼來源:MediaNotificationManager.java

示例11: updateMainNotification

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private void updateMainNotification(State state) {
    NotificationCompat.Builder notification = mainNotification();
    notification.mActions.clear();

    Song songPlaying = state.songPlaying;
    notification.setContentTitle(songPlaying.name);
    notification.setContentText(songPlaying.artist);
    notification.setTicker("Playing " + songPlaying.name);

    // Skip previous action
    Intent intentSkipPrevious = new Intent(this, NotificationSkipPreviousReceiver.class);
    intentSkipPrevious.putExtra("com.my.app.notificationId", notificationId);
    PendingIntent pendingPrevious = PendingIntent.getBroadcast(this, notificationId, intentSkipPrevious, 0);
    notification.addAction(R.drawable.ic_skip_previous, "", pendingPrevious);

    // Play/pause action
    Intent intentPlayPause = new Intent(this, NotificationPlayPauseReceiver.class);
    intentPlayPause.putExtra("com.my.app.notificationId", notificationId);
    PendingIntent pendingPlayPause = PendingIntent.getBroadcast(this, notificationId, intentPlayPause, 0);
    notification.addAction(state.isPaused ? R.drawable.ic_play : R.drawable.ic_pause, "", pendingPlayPause);

    // Skip next action
    Intent intentSkipNext = new Intent(this, NotificationSkipNextReceiver.class);
    intentSkipNext.putExtra("com.my.app.notificationId", notificationId);
    PendingIntent pendingNext = PendingIntent.getBroadcast(this, notificationId, intentSkipNext, 0);
    notification.addAction(R.drawable.ic_skip_next, "", pendingNext);

    notify(notificationId, notification);
}
 
開發者ID:sovteam,項目名稱:buddybox,代碼行數:30,代碼來源:MainActivity.java

示例12: onCreate

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    remoteViews = new RemoteViews(getPackageName(),R.layout.notification_data);
    builder.setContent(remoteViews);
    builder.setSmallIcon(R.mipmap.app_icon);
    notification = builder.getNotification();
    startForeground(1,notification);
    CFLog.e(this.getClass().getName(),"onCreate");
}
 
開發者ID:stdnull,項目名稱:RunMap,代碼行數:12,代碼來源:MoveHintForeService.java

示例13: onStart

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
@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);
}
 
開發者ID:yufeilong92,項目名稱:update-master,代碼行數:16,代碼來源:UpdateAgent.java

示例14: showUpdateNotification

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private void showUpdateNotification() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notificationIntent = MainActivity.createIntent(this, false);
    PendingIntent intent = PendingIntent.getActivity(this, 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder notBuilder = getBasetNotification();
    notBuilder.setContentTitle(getString(R.string.newUpdateNotificationText))
            .setContentText(getString(R.string.newUpdateNotificationContentText))
            .setContentIntent(intent);

    nm.notify(NOTID, notBuilder.build());
}
 
開發者ID:bamless,項目名稱:chromium-swe-updater,代碼行數:14,代碼來源:CheckUpdateService.java

示例15: sendRichTextNotifi

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
/**
 * 發送富文本通知(大圖片/長文字)
 */
private void sendRichTextNotifi() {
    Log.e("發送富文本", "執行了");
    builder = new NotificationCompat.Builder(this);
    NotificationCompat.BigPictureStyle bigPictureStyle =
            new android.support.v4.app.NotificationCompat.BigPictureStyle();
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(getResources(), R.drawable.train_online, options);

    int inSampleSize = (int) (options.outHeight * 1f / dip2px(256));
    Log.e("圖片高度+256dp的值", options.outHeight + "+++++++++" + dip2px(256));
    options.inJustDecodeBounds = false;
    options.inSampleSize = inSampleSize;
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.train_online, options);

    bigPictureStyle.bigLargeIcon(this.bitmap)
            .bigPicture(bitmap)
            .setBigContentTitle("大圖片通知");

    notification = builder.setStyle(bigPictureStyle)
            .setContentTitle("恭喜您中獎了")
            .setContentIntent(pendingIntent)
            .setLargeIcon(this.bitmap)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentText("您有一條消息")
            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
            .setAutoCancel(true)
            .build();
    manager.notify(2, notification);
}
 
開發者ID:BittleDragon,項目名稱:MyRepository,代碼行數:34,代碼來源:MainActivity.java


注:本文中的android.support.v7.app.NotificationCompat.Builder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。