本文整理匯總了Java中android.support.v7.app.NotificationCompat.Action方法的典型用法代碼示例。如果您正苦於以下問題:Java NotificationCompat.Action方法的具體用法?Java NotificationCompat.Action怎麽用?Java NotificationCompat.Action使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.app.NotificationCompat
的用法示例。
在下文中一共展示了NotificationCompat.Action方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getForwardAction
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
/**
* Returns the {@link NotificationCompat.Action} for forwarding the current media by
* {@code millis} milliseconds.
*/
protected NotificationCompat.Action getForwardAction(long millis) {
Intent intent = new Intent(this, VideoIntentReceiver.class);
intent.setAction(ACTION_FORWARD);
intent.setPackage(getPackageName());
intent.putExtra(EXTRA_FORWARD_STEP_MS, (int) millis);
PendingIntent pendingIntent = PendingIntent
.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int iconResourceId = R.drawable.ic_notification_forward_48dp;
if (millis == TEN_SECONDS_MILLIS) {
iconResourceId = R.drawable.ic_notification_forward10_48dp;
} else if (millis == THIRTY_SECONDS_MILLIS) {
iconResourceId = R.drawable.ic_notification_forward30_48dp;
}
return new NotificationCompat.Action.Builder(iconResourceId,
getString(R.string.ccl_forward), pendingIntent).build();
}
示例2: getRewindAction
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
/**
* Returns the {@link NotificationCompat.Action} for rewinding the current media by
* {@code millis} milliseconds.
*/
protected NotificationCompat.Action getRewindAction(long millis) {
Intent intent = new Intent(this, VideoIntentReceiver.class);
intent.setAction(ACTION_REWIND);
intent.setPackage(getPackageName());
intent.putExtra(EXTRA_FORWARD_STEP_MS, (int)-millis);
PendingIntent pendingIntent = PendingIntent
.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int iconResourceId = R.drawable.ic_notification_rewind_48dp;
if (millis == TEN_SECONDS_MILLIS) {
iconResourceId = R.drawable.ic_notification_rewind10_48dp;
} else if (millis == THIRTY_SECONDS_MILLIS) {
iconResourceId = R.drawable.ic_notification_rewind30_48dp;
}
return new NotificationCompat.Action.Builder(iconResourceId,
getString(R.string.ccl_rewind), pendingIntent).build();
}
示例3: getSkipNextAction
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
/**
* Returns the {@link NotificationCompat.Action} for skipping to the next item in the queue. If
* we are already at the end of the queue, we show a dimmed version of the icon for this action
* and won't send any {@link PendingIntent}
*/
protected NotificationCompat.Action getSkipNextAction() {
PendingIntent pendingIntent = null;
int iconResourceId = R.drawable.ic_notification_skip_next_semi_48dp;
if (mHasNext) {
Intent intent = new Intent(this, VideoIntentReceiver.class);
intent.setAction(ACTION_PLAY_NEXT);
intent.setPackage(getPackageName());
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
iconResourceId = R.drawable.ic_notification_skip_next_48dp;
}
return new NotificationCompat.Action.Builder(iconResourceId,
getString(R.string.ccl_skip_next), pendingIntent).build();
}
示例4: getPlayPauseAction
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
/**
* Returns the {@link NotificationCompat.Action} for toggling play/pause/stop of the currently
* playing item.
*/
protected NotificationCompat.Action getPlayPauseAction(MediaInfo info, boolean isPlaying) {
int pauseOrStopResourceId;
if (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) {
pauseOrStopResourceId = R.drawable.ic_notification_stop_48dp;
} else {
pauseOrStopResourceId = R.drawable.ic_notification_pause_48dp;
}
int pauseOrPlayTextResourceId = isPlaying ? R.string.ccl_pause : R.string.ccl_play;
int pauseOrPlayResourceId = isPlaying ? pauseOrStopResourceId
: R.drawable.ic_notification_play_48dp;
Intent intent = new Intent(this, VideoIntentReceiver.class);
intent.setAction(ACTION_TOGGLE_PLAYBACK);
intent.setPackage(getPackageName());
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
return new NotificationCompat.Action.Builder(pauseOrPlayResourceId,
getString(pauseOrPlayTextResourceId), pendingIntent).build();
}
示例5: buildNotification
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private void buildNotification( NotificationCompat.Action action ) {
lastNotificationAction = action;
Intent intent = new Intent( getApplicationContext(), PlayerService.class );
intent.setAction( ACTION_STOP );
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0);
Class toClass = isVod ? VODActivity.class : LiveStreamActivity.class;
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this).addParentStack(toClass).addNextIntent(mNotificationIntent);
PendingIntent onClickPendingIntent = stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
NotificationCompat.Builder noti = (NotificationCompat.Builder) new NotificationCompat.Builder( this )
.setSmallIcon( R.drawable.ic_notification_icon_refresh )
.setContentTitle( mChannelInfo.getDisplayName() )
.setDeleteIntent( pendingIntent )
.addAction(action)
.addAction(generateAction(R.drawable.ic_clear_black_36dp, getString(R.string.stop_lower), ACTION_STOP))
.setStyle(new NotificationCompat.MediaStyle()
.setMediaSession(mediaSession.getSessionToken())
.setShowCancelButton(true)
.setShowActionsInCompactView(0,1)
)
.setShowWhen(false)
.setAutoCancel(false)
.setContentIntent(onClickPendingIntent);
if (mChannelInfo.getLogoImage() != null) {
noti.setLargeIcon(mChannelInfo.getLogoImage());
}
NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE );
notificationManager.notify( NOTIFICATION_ID, noti.build() );
}
示例6: getSkipPreviousAction
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
/**
* Returns the {@link NotificationCompat.Action} for skipping to the previous item in the queue.
* If we are already at the beginning of the queue, we show a dimmed version of the icon for
* this action and won't send any {@link PendingIntent}
*/
protected NotificationCompat.Action getSkipPreviousAction() {
PendingIntent pendingIntent = null;
int iconResourceId = R.drawable.ic_notification_skip_prev_semi_48dp;
if (mHasPrev) {
Intent intent = new Intent(this, VideoIntentReceiver.class);
intent.setAction(ACTION_PLAY_PREV);
intent.setPackage(getPackageName());
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
iconResourceId = R.drawable.ic_notification_skip_prev_48dp;
}
return new NotificationCompat.Action.Builder(iconResourceId,
getString(R.string.ccl_skip_previous), pendingIntent).build();
}
示例7: getDisconnectAction
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
/**
* Returns the {@link NotificationCompat.Action} for disconnecting this app from the cast
* device.
*/
protected NotificationCompat.Action getDisconnectAction() {
Intent intent = new Intent(this, VideoIntentReceiver.class);
intent.setAction(ACTION_STOP);
intent.setPackage(getPackageName());
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
return new NotificationCompat.Action.Builder(R.drawable.ic_notification_disconnect_24dp,
getString(R.string.ccl_disconnect), pendingIntent).build();
}
示例8: mediaStyleNotification
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private Notification mediaStyleNotification() {
Intent intent = new Intent(getApplicationContext(), NowPlayingActivity.class);
intent.putExtra("LAUNCHED_FROM_NOTIFICATION", true);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
int color = getSongDataHelper().getColor();
Logger.exp("AAAAAA " + color);
NotificationCompat.Action action;
if (!isPlayingMusic()) {
action = generateAction(R.drawable.btn_playback_play_light, "Play", Constants.ACTION_PAUSE);
} else {
action = generateAction(R.drawable.btn_playback_pause_light, "Pase", Constants.ACTION_PAUSE);
}
return new NotificationCompat.Builder(this)
.addAction(generateAction(R.drawable.btn_playback_previous_light, "Previous", Constants.ACTION_PREVIOUS))
.addAction(action)
.addAction(generateAction(R.drawable.btn_playback_next_light, "Previous", Constants.ACTION_NEXT))
.setSmallIcon(R.mipmap.ic_music_file)
.setContentTitle(getSongDataHelper().getTitle())
.setContentIntent(pendingIntent)
.setContentText(getSongDataHelper().getAlbum())
.setLargeIcon(getSongDataHelper().getAlbumArt())
.setColor(color)
.setStyle(new NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0, 1, 2)
.setMediaSession(mMediaSession.getSessionToken()))
.build();
}
示例9: pause
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private NotificationCompat.Action pause(Context context){
Intent playPauseIntent=new Intent(context,MusicPlaybackService.class);
playPauseIntent.setAction(ACTION_PAUSE);
PendingIntent pausePendingIntent=PendingIntent.getService(context,
PAUSE_PENDING_INTENT_ID,
playPauseIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
return new NotificationCompat.Action(R.drawable.ic_pause_notif,"Pause",pausePendingIntent);
}
示例10: next
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private NotificationCompat.Action next(Context context){
Intent nextIntent=new Intent(context,MusicPlaybackService.class);
nextIntent.setAction(ACTION_NEXT);
PendingIntent nextPendingIntent=PendingIntent.getService(context,
PLAY_NEXT_PENDING_INTENT_ID,
nextIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
return new NotificationCompat.Action(R.drawable.ic_skip_next_notif,"Next",nextPendingIntent);
}
示例11: prev
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private NotificationCompat.Action prev(Context context){
Intent prevIntent=new Intent(context,MusicPlaybackService.class);
prevIntent.setAction(ACTION_PREV);
PendingIntent prevPendingIntent=PendingIntent.getService(context,
PLAY_PREV_PENDING_INTENT_ID,
prevIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
return new NotificationCompat.Action(R.drawable.ic_skip_prev_notif,"Previous",prevPendingIntent);
}
示例12: play
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private NotificationCompat.Action play(Context context){
Intent prevIntent=new Intent(context,MusicPlaybackService.class);
prevIntent.setAction(ACTION_PLAY);
PendingIntent prevPendingIntent=PendingIntent.getService(context,
PLAY_PENDING_INTENT_ID,
prevIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
return new NotificationCompat.Action(R.drawable.ic_play_notif,"Play",prevPendingIntent);
}
示例13: MediaNotificationManager
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
public MediaNotificationManager(MusicService service) {
mService = service;
String pkg = mService.getPackageName();
PendingIntent playIntent =
PendingIntent.getBroadcast(
mService,
REQUEST_CODE,
new Intent(ACTION_PLAY).setPackage(pkg),
PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pauseIntent =
PendingIntent.getBroadcast(
mService,
REQUEST_CODE,
new Intent(ACTION_PAUSE).setPackage(pkg),
PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent nextIntent =
PendingIntent.getBroadcast(
mService,
REQUEST_CODE,
new Intent(ACTION_NEXT).setPackage(pkg),
PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent prevIntent =
PendingIntent.getBroadcast(
mService,
REQUEST_CODE,
new Intent(ACTION_PREV).setPackage(pkg),
PendingIntent.FLAG_CANCEL_CURRENT);
mPlayAction =
new NotificationCompat.Action(
R.drawable.ic_play_arrow_white_24dp,
mService.getString(R.string.label_play),
playIntent);
mPauseAction =
new NotificationCompat.Action(
R.drawable.ic_pause_white_24dp,
mService.getString(R.string.label_pause),
pauseIntent);
mNextAction =
new NotificationCompat.Action(
R.drawable.ic_skip_next_white_24dp,
mService.getString(R.string.label_next),
nextIntent);
mPrevAction =
new NotificationCompat.Action(
R.drawable.ic_skip_previous_white_24dp,
mService.getString(R.string.label_previous),
prevIntent);
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_NEXT);
filter.addAction(ACTION_PAUSE);
filter.addAction(ACTION_PLAY);
filter.addAction(ACTION_PREV);
mService.registerReceiver(this, filter);
mNotificationManager =
(NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE);
// Cancel all notifications to handle the case where the Service was killed and
// restarted by the system.
mNotificationManager.cancelAll();
}
示例14: generateAction
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private NotificationCompat.Action generateAction( int icon, String title, String intentAction ) {
Intent intent = new Intent( getApplicationContext(), PlayerService.class );
intent.setAction( intentAction );
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0);
return new NotificationCompat.Action.Builder( icon, title, pendingIntent ).build();
}
示例15: generateAction
import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private NotificationCompat.Action generateAction(int icon, String title, String intentAction) {
Intent intent = new Intent(getApplicationContext(), MusicService.class);
intent.setAction(intentAction);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0);
return new NotificationCompat.Action.Builder(icon, title, pendingIntent).build();
}