Java Code Examples for android.app.Service#stopForeground()

The following examples show how to use android.app.Service#stopForeground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdamantLocalMessagingService.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
private static void stopForeground(WeakReference<AdamantLocalMessagingService> serviceWeakReference) {
    Service service = serviceWeakReference.get();
    if (service != null) {
        service.stopForeground(true);
        service.stopSelf();
    }
}
 
Example 2
Source File: SaveContactsService.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
private static void stopForeground(WeakReference<Service> serviceWeakReference) {
    Service service = serviceWeakReference.get();
    if (service != null) {
        service.stopForeground(true);
        service.stopSelf();
    }
}
 
Example 3
Source File: NotificationUtil.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * DConnectServiceがOFF時にstartForegroundService()が行われた時にキャンセルする.
 */
public static void fakeStartForeground(final Service service,
                                       final String channelId,
                                       final String title,
                                       final String description,
                                       final int notificationId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        Notification.Builder builder = new Notification.Builder(service.getApplicationContext(),
                                channelId)
                .setContentTitle("").setContentText("");
        NotificationChannel channel = new NotificationChannel(
                channelId,
                title,
                NotificationManager.IMPORTANCE_LOW);
        channel.setDescription(description);
        int iconType = Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ?
                R.drawable.icon : R.drawable.on_icon;
        builder.setSmallIcon(iconType);
        NotificationManager mNotification = (NotificationManager) service.getApplicationContext()
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotification.createNotificationChannel(channel);
        builder.setChannelId(channelId);
        service.startForeground(notificationId, builder.build());
        service.stopForeground(true);
        service.stopSelf();
    }
}
 
Example 4
Source File: NotificationUtil.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
/**
 * フォアグランドを停止する。
 */
public static void hideNotification(final Service service) {
    service.stopForeground(true);
}
 
Example 5
Source File: DownloadingService.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
static void stopForeground(Service service) {
    service.stopForeground(true);
}
 
Example 6
Source File: TabsTrackerService.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
static void stopForeground(Service service) {
    service.stopForeground(true);
}
 
Example 7
Source File: Ntf.java    From screen-dimmer-pixel-filter with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void show(Service ctx, boolean enable) {
    NotificationManager ntfMgr = (NotificationManager)ctx.getSystemService(Service.NOTIFICATION_SERVICE);

    if (enable || Cfg.PersistentNotification) {
        PendingIntent edit = PendingIntent.getActivity(ctx, 0, new Intent(Intent.ACTION_EDIT, null, ctx, MainActivity.class), PendingIntent.FLAG_CANCEL_CURRENT);
        PendingIntent cancel = PendingIntent.getService(ctx, 0, new Intent(enable ? Intent.ACTION_DELETE : Intent.ACTION_RUN, null, ctx, FilterService.class), PendingIntent.FLAG_CANCEL_CURRENT);
        PendingIntent increase = PendingIntent.getService(ctx, 0, new Intent(ctx.getString(R.string.intent_darker), null, ctx, FilterService.class), PendingIntent.FLAG_CANCEL_CURRENT);
        PendingIntent decrease = PendingIntent.getService(ctx, 0, new Intent(ctx.getString(R.string.intent_brighter), null, ctx, FilterService.class), PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Action.Builder ntf_act_increase = new NotificationCompat.Action.Builder(R.drawable.ic_add_circle_outline,
                ctx.getString(R.string.darker), increase);
        NotificationCompat.Action.Builder ntf_act_decrease = new NotificationCompat.Action.Builder(R.drawable.ic_remove_circle_outline,
                ctx.getString(R.string.brighter), decrease);
        NotificationCompat.Action.Builder ntf_act_configure = new NotificationCompat.Action.Builder(R.drawable.ic_build,
                ctx.getString(R.string.configure), edit);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)
                .setContentTitle(ctx.getString(R.string.app_name) +
                        (enable ? " - " + Grids.PatternNames[Cfg.Pattern] : ""))
                .setContentText(enable ? ctx.getString(R.string.tap_to_disable) : ctx.getString(R.string.enable_filter_checkbox))
                .setContentInfo(ctx.getString(R.string.swipe_to_configure))
                .setContentIntent(cancel)
                .addAction(ntf_act_configure.build())
                .addAction(ntf_act_increase.build())
                .addAction(ntf_act_decrease.build())
                .setDeleteIntent(cancel)
                .setPriority(Cfg.HideNotification ? NotificationCompat.PRIORITY_MIN : NotificationCompat.PRIORITY_LOW)
                .setSmallIcon(R.drawable.notification)
                .setSound(null)
                .setOngoing(true)
                .setLocalOnly(true)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setTicker(null)
                .setShowWhen(false);

        Notification ntf = builder.build();
        ctx.startForeground(NTF_ID, ntf);
    } else {
        ctx.stopForeground(true);
        ntfMgr.cancel(NTF_ID);
    }
}
 
Example 8
Source File: MainServiceForegroundStarter.java    From JayPS-AndroidApp with MIT License 4 votes vote down vote up
@Override
public void stopServiceForeground(Service service) {
    service.stopForeground(true);
    builder = null;
}