本文整理匯總了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);
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
}
示例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><string name="name">%s is connected</string></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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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");
}
示例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);
}
示例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());
}
示例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);
}