当前位置: 首页>>代码示例>>Java>>正文


Java Service.startForeground方法代码示例

本文整理汇总了Java中android.app.Service.startForeground方法的典型用法代码示例。如果您正苦于以下问题:Java Service.startForeground方法的具体用法?Java Service.startForeground怎么用?Java Service.startForeground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.Service的用法示例。


在下文中一共展示了Service.startForeground方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createNotification

import android.app.Service; //导入方法依赖的package包/类
public static void createNotification(Service context) {
    // Create Pending Intents.
    PendingIntent piLaunchMainActivity = getLaunchActivityPI(context);
    PendingIntent piStopService = getStopServicePI(context);

    // Action to stop the service.
    NotificationCompat.Action stopAction =
            new NotificationCompat.Action.Builder(
                            STOP_ACTION_ICON,
                            getNotificationStopActionText(context),
                            piStopService)
                    .build();

    // Create a notification.
    Notification mNotification =
            new NotificationCompat.Builder(context)
                    .setContentTitle(getNotificationTitle(context))
                    .setContentText(getNotificationContent(context))
                    .setSmallIcon(SMALL_ICON)
                    .setContentIntent(piLaunchMainActivity)
                    .addAction(stopAction)
                    .setStyle(new NotificationCompat.BigTextStyle())
                    .build();

    context.startForeground(ONGOING_NOTIFICATION_ID, mNotification);
}
 
开发者ID:r3bl-alliance,项目名称:stay-awake-app,代码行数:27,代码来源:HandleNotifications.java

示例2: createStopNotification

import android.app.Service; //导入方法依赖的package包/类
public static void createStopNotification(MediaSessionCompat mediaSession, Service context, Class<?> serviceClass, int NOTIFICATION_ID) {

        PendingIntent stopIntent = PendingIntent
                .getService(context, 0, getIntent(MediaRecorderService.REQUEST_TYPE_STOP, context, serviceClass),
                        PendingIntent.FLAG_CANCEL_CURRENT);

        MediaControllerCompat controller = mediaSession.getController();
        MediaMetadataCompat mediaMetadata = controller.getMetadata();
        MediaDescriptionCompat description = mediaMetadata.getDescription();
        // Start foreground service to avoid unexpected kill
        Notification notification = new NotificationCompat.Builder(context)
                .setContentTitle(description.getTitle())
                .setContentText(description.getSubtitle())
                .setSubText(description.getDescription())
                .setLargeIcon(description.getIconBitmap())
                .setDeleteIntent(stopIntent)
                // Add a pause button
                .addAction(new android.support.v7.app.NotificationCompat.Action(
                        R.drawable.ic_stop_black_24dp, context.getString(R.string.stop),
                        MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_STOP)))
                .setStyle(new android.support.v7.app.NotificationCompat.MediaStyle()
                        .setMediaSession(mediaSession.getSessionToken())
                        .setShowActionsInCompactView(0)
                        .setShowCancelButton(true)
                        .setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_STOP)))
                .setSmallIcon(R.drawable.ic_album_black_24dp)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .build();

        context.startForeground(NOTIFICATION_ID, notification);
    }
 
开发者ID:aschober,项目名称:vinyl-cast,代码行数:34,代码来源:Helpers.java

示例3: show

import android.app.Service; //导入方法依赖的package包/类
public static void show(final Service service, MediaSessionCompat session, Station station, int stationID, String stationMetadata) {
    // save service and session
    mService = service;
    mSession = session;
    mStationMetadata = stationMetadata;

    // build notification
    station.setPlaybackState(true);
    mNotification = getNotificationBuilder(station, stationID, mStationMetadata).build(); // TODO: change -> Station object contains metadata, too

    // display notification
    service.startForeground(PLAYER_SERVICE_NOTIFICATION_ID, mNotification);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:14,代码来源:NotificationHelper.java

示例4: show

import android.app.Service; //导入方法依赖的package包/类
public static void show(final Service service, MediaSessionCompat session, Station station, int stationID, String stationMetadata) {
    // save service and session
    mService = service;
    mSession = session;
    mStationMetadata = stationMetadata;

    // build notification
    ////comment unneeded setPlaybackState
    //station.setPlaybackState(true);
    mNotification = getNotificationBuilder(station, stationID, mStationMetadata).build(); // TODO: change -> Station object contains metadata, too

    // display notification
    service.startForeground(TransistorKeys.PLAYER_SERVICE_NOTIFICATION_ID, mNotification);
}
 
开发者ID:malah-code,项目名称:Open-Quran-Radio,代码行数:15,代码来源:NotificationHelper.java

示例5: showRunningNotification

import android.app.Service; //导入方法依赖的package包/类
@Override
public void showRunningNotification(Service context) {
	context.startForeground(ONLINE_NOTIFICATION, newRunningNotification(context));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:ConnectionNotifier.java


注:本文中的android.app.Service.startForeground方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。