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


Java NotificationCompat.MediaStyle方法代碼示例

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


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

示例1: build

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
@Override
public void build() {
    super.build();
    NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle();
    style.setMediaSession(new MediaSessionCompat(NotifyUtil.getInstance().getContext(),"MediaSession",
            new ComponentName(NotifyUtil.getInstance().getContext(), Intent.ACTION_MEDIA_BUTTON),null).getSessionToken());
    //設置要現實在通知右方的圖標 最多三個
    style.setShowActionsInCompactView(2,3);
    style.setShowCancelButton(true);
    cBuilder.setStyle(style);
    cBuilder.setShowWhen(false);
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:13,代碼來源:MediaBuilder.java

示例2: buildNotification

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private Notification buildNotification() {
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();
    String text = TextUtils.isEmpty(albumName)
            ? artistName : artistName + " - " + albumName;

    int playButtonResId = isPlaying
            ? R.drawable.ic_pause_white_36dp : R.drawable.ic_play_white_36dp;

    Intent nowPlayingIntent = NavigationUtils.getNowPlayingIntent(this);
    PendingIntent clickIntent = PendingIntent.getActivity(this, 0, nowPlayingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Bitmap artwork;
    artwork = ImageLoader.getInstance().loadImageSync(TimberUtils.getAlbumArtUri(getAlbumId()).toString());

    if (artwork == null) {
        artwork = ImageLoader.getInstance().loadImageSync("drawable://" + R.drawable.ic_empty_music2);
    }

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }

    android.support.v4.app.NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification)
            .setLargeIcon(artwork)
            .setContentIntent(clickIntent)
            .setContentTitle(getTrackName())
            .setContentText(text)
            .setWhen(mNotificationPostTime)
            .addAction(R.drawable.ic_skip_previous_white_36dp,
                    "",
                    retrievePlaybackAction(PREVIOUS_ACTION))
            .addAction(playButtonResId, "",
                    retrievePlaybackAction(TOGGLEPAUSE_ACTION))
            .addAction(R.drawable.ic_skip_next_white_36dp,
                    "",
                    retrievePlaybackAction(NEXT_ACTION));

    if (TimberUtils.isJellyBeanMR1()) {
        builder.setShowWhen(false);
    }
    if (TimberUtils.isLollipop()) {
        builder.setVisibility(Notification.VISIBILITY_PUBLIC);
        NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle()
                .setMediaSession(mSession.getSessionToken())
                .setShowActionsInCompactView(0, 1, 2, 3);
        builder.setStyle(style);
    }
    if (artwork != null && TimberUtils.isLollipop())
        builder.setColor(Palette.from(artwork).generate().getVibrantColor(Color.parseColor("#403f4d")));
    Notification n = builder.build();

    if (mActivateXTrackSelector) {
        addXTrackSelector(n);
    }

    return n;
}
 
開發者ID:Vinetos,項目名稱:Hello-Music-droid,代碼行數:60,代碼來源:MusicService.java

示例3: addNotificationButtons

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private void addNotificationButtons(NotificationCompat.Builder builder) {
    // Only apply MediaStyle when NotificationInfo supports play/pause.
    if (mMediaNotificationInfo.supportsPlayPause()) {
        NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle();
        style.setMediaSession(mMediaSession.getSessionToken());

        int numAddedActions = 0;

        if (mMediaNotificationInfo.mediaSessionActions.contains(
                    MediaSessionAction.PREVIOUS_TRACK)) {
            builder.addAction(R.drawable.ic_media_control_skip_previous,
                    mPreviousTrackDescription,
                    createPendingIntent(ListenerService.ACTION_PREVIOUS_TRACK));
            ++numAddedActions;
        }
        if (mMediaNotificationInfo.isPaused) {
            builder.addAction(R.drawable.ic_media_control_play, mPlayDescription,
                    createPendingIntent(ListenerService.ACTION_PLAY));
        } else {
            // If we're here, the notification supports play/pause button and is playing.
            builder.addAction(R.drawable.ic_media_control_pause, mPauseDescription,
                    createPendingIntent(ListenerService.ACTION_PAUSE));
        }
        ++numAddedActions;
        if (mMediaNotificationInfo.mediaSessionActions.contains(
                    MediaSessionAction.NEXT_TRACK)) {
            builder.addAction(R.drawable.ic_media_control_skip_next, mNextTrackDescription,
                    createPendingIntent(ListenerService.ACTION_NEXT_TRACK));
            ++numAddedActions;
        }
        numAddedActions = Math.min(numAddedActions, MAXIMUM_NUM_ACTIONS_IN_COMPACT_VIEW);
        int[] compactViewActions = new int[numAddedActions];
        for (int i = 0; i < numAddedActions; ++i) compactViewActions[i] = i;
        style.setShowActionsInCompactView(compactViewActions);
        style.setCancelButtonIntent(createPendingIntent(ListenerService.ACTION_CANCEL));
        style.setShowCancelButton(true);
        builder.setStyle(style);
    }

    if (mMediaNotificationInfo.supportsStop()) {
        builder.addAction(R.drawable.ic_media_control_stop, mStopDescription,
                createPendingIntent(ListenerService.ACTION_STOP));
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:45,代碼來源:MediaNotificationManager.java

示例4: buildNotification

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
/**
 * Builds notification panel with buttons and info on it
 *
 * @param action Action to be applied
 */

private void buildNotification(NotificationCompat.Action action) {

    final NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle();

    Intent intent = new Intent(getApplicationContext(), BackgroundAudioService.class);
    intent.setAction(ACTION_STOP);
    PendingIntent stopPendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0);

    Intent clickIntent = new Intent(this, MainActivity.class);
    clickIntent.setAction(Intent.ACTION_MAIN);
    clickIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    PendingIntent clickPendingIntent = PendingIntent.getActivity(this, 0, clickIntent, 0);

    builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.ic_small_icon);
    builder.setContentTitle(videoItem.getTitle());
    builder.setContentInfo(videoItem.getDuration());
    builder.setShowWhen(false);
    builder.setContentIntent(clickPendingIntent);
    builder.setDeleteIntent(stopPendingIntent);
    builder.setOngoing(false);
    builder.setSubText(videoItem.getViewCount());
    builder.setStyle(style);

    //load bitmap for largeScreen
    if (videoItem.getThumbnailURL() != null && !videoItem.getThumbnailURL().isEmpty()) {
        Picasso.with(this)
                .load(videoItem.getThumbnailURL())
                .into(target);
    }

    builder.addAction(generateAction(R.drawable.ic_previous, "Previous", ACTION_PREVIOUS));
    builder.addAction(action);
    builder.addAction(generateAction(R.drawable.ic_next, "Next", ACTION_NEXT));
    style.setShowActionsInCompactView(0, 1, 2);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, builder.build());
}
 
開發者ID:pawelpaszki,項目名稱:youtube_background_android,代碼行數:46,代碼來源:BackgroundAudioService.java

示例5: getNotificationBuilder

import android.support.v7.app.NotificationCompat; //導入方法依賴的package包/類
private static NotificationCompat.Builder getNotificationBuilder(Station station, int stationID_Position, String stationMetadata) {

        // explicit intent for notification tap
        Intent tapActionIntent = new Intent(mService, MainActivity.class);
        tapActionIntent.setAction(TransistorKeys.ACTION_SHOW_PLAYER);
        tapActionIntent.putExtra(TransistorKeys.EXTRA_STATION, station);
        tapActionIntent.putExtra(TransistorKeys.EXTRA_STATION_Position_ID, stationID_Position);

        // explicit intent for stopping playback
        Intent stopActionIntent = new Intent(mService, PlayerService.class);
        stopActionIntent.setAction(TransistorKeys.ACTION_STOP);

        // explicit intent for starting playback
        Intent playActionIntent = new Intent(mService, PlayerService.class);
        playActionIntent.setAction(TransistorKeys.ACTION_PLAY);

        // explicit intent for swiping notification
        Intent swipeActionIntent = new Intent(mService, PlayerService.class);
        swipeActionIntent.setAction(TransistorKeys.ACTION_DISMISS);

        // artificial back stack for started Activity.
        // -> navigating backward from the Activity leads to Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(mService);
//        // backstack: adds back stack for Intent (but not the Intent itself)
//        stackBuilder.addParentStack(MainActivity.class);
        // backstack: add explicit intent for notification tap
        stackBuilder.addNextIntent(tapActionIntent);

        // pending intent wrapper for notification tap
        PendingIntent tapActionPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
//        PendingIntent tapActionPendingIntent = PendingIntent.getService(mService, 0, tapActionIntent, 0);
        // pending intent wrapper for notification stop action
        PendingIntent stopActionPendingIntent = PendingIntent.getService(mService, 10, stopActionIntent, 0);
        // pending intent wrapper for notification start action
        PendingIntent playActionPendingIntent = PendingIntent.getService(mService, 11, playActionIntent, 0);
        // pending intent wrapper for notification swipe action
        PendingIntent swipeActionPendingIntent = PendingIntent.getService(mService, 12, swipeActionIntent, 0);

        // create media style
        NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle();
        style.setMediaSession(mSession.getSessionToken());
        style.setShowActionsInCompactView(0);
        style.setShowCancelButton(true); // pre-Lollipop workaround
        style.setCancelButtonIntent(swipeActionPendingIntent);

        // construct notification in builder
        NotificationCompat.Builder builder;
        builder = new NotificationCompat.Builder(mService);
        builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        builder.setSmallIcon(R.drawable.ic_notification_small_24dp);
        builder.setLargeIcon(getStationIcon(mService, station));
        builder.setContentTitle(station.TITLE);
        builder.setContentText(stationMetadata);
        builder.setShowWhen(false);
        builder.setStyle(style);
        builder.setContentIntent(tapActionPendingIntent);
        builder.setDeleteIntent(swipeActionPendingIntent);

        if (station.getPlaybackState()) {
            builder.addAction(R.drawable.ic_stop_white_36dp, mService.getString(R.string.notification_stop), stopActionPendingIntent);
        } else {
            builder.addAction(R.drawable.ic_play_arrow_white_36dp, mService.getString(R.string.notification_play), playActionPendingIntent);
        }

        return builder;
    }
 
開發者ID:malah-code,項目名稱:Open-Quran-Radio,代碼行數:67,代碼來源:NotificationHelper.java


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