Example usage for android.app Service startActivity

List of usage examples for android.app Service startActivity

Introduction

In this page you can find the example usage for android.app Service startActivity.

Prototype

@Override
    public void startActivity(Intent intent) 

Source Link

Usage

From source file:com.wizardsofm.deskclock.alarms.AlarmNotifications.java

public static void showAlarmNotification(Service service, AlarmInstance instance) {
    LogUtils.v("Displaying alarm notification for alarm instance: " + instance.mId);

    Resources resources = service.getResources();
    NotificationCompat.Builder notification = new NotificationCompat.Builder(service)
            .setContentTitle(instance.getLabelOrDefault(service))
            .setContentText(AlarmUtils.getFormattedTime(service, instance.getAlarmTime()))
            .setColor(ContextCompat.getColor(service, com.wizardsofm.deskclock.R.color.default_background))
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_alarm).setOngoing(true)
            .setAutoCancel(false).setDefaults(NotificationCompat.DEFAULT_LIGHTS).setWhen(0)
            .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setLocalOnly(true);/*w  w  w. j  a  v a 2 s  . c  o  m*/

    // Setup Snooze Action
    Intent snoozeIntent = AlarmStateManager.createStateChangeIntent(service, AlarmStateManager.ALARM_SNOOZE_TAG,
            instance, AlarmInstance.SNOOZE_STATE);
    snoozeIntent.putExtra(AlarmStateManager.FROM_NOTIFICATION_EXTRA, true);
    PendingIntent snoozePendingIntent = PendingIntent.getService(service, instance.hashCode(), snoozeIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.addAction(com.wizardsofm.deskclock.R.drawable.ic_snooze_24dp,
            resources.getString(com.wizardsofm.deskclock.R.string.alarm_alert_snooze_text),
            snoozePendingIntent);

    // Setup Dismiss Action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(service,
            AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE);
    dismissIntent.putExtra(AlarmStateManager.FROM_NOTIFICATION_EXTRA, true);
    PendingIntent dismissPendingIntent = PendingIntent.getService(service, instance.hashCode(), dismissIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.addAction(com.wizardsofm.deskclock.R.drawable.ic_alarm_off_24dp,
            resources.getString(com.wizardsofm.deskclock.R.string.alarm_alert_dismiss_text),
            dismissPendingIntent);

    // Setup Content Action
    Intent contentIntent = AlarmInstance.createIntent(service, AlarmActivity.class, instance.mId);
    notification.setContentIntent(PendingIntent.getActivity(service, instance.hashCode(), contentIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup fullscreen intent
    Intent fullScreenIntent = AlarmInstance.createIntent(service, AlarmActivity.class, instance.mId);

    // set action, so we can be different then content pending intent
    fullScreenIntent.setAction("fullscreen_activity");
    fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // |Intent.FLAG_ACTIVITY_NO_USER_ACTION
    //        fullScreenIntent.addFlags(FLAG_FULLSCREEN +FLAG_SHOW_WHEN_LOCKED +  FLAG_TURN_SCREEN_ON
    //                + FLAG_DISMISS_KEYGUARD + FLAG_KEEP_SCREEN_ON);
    service.startActivity(fullScreenIntent);

    //        notification.setFullScreenIntent(PendingIntent.getActivity(service,
    //                instance.hashCode(), fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT), true);
    //        notification.setPriority(NotificationCompat.PRIORITY_MAX);
    //
    //        clearNotification(service, instance);
    //        service.startForeground(instance.hashCode(), notification.build());
}