Example usage for android.app Service getApplicationContext

List of usage examples for android.app Service getApplicationContext

Introduction

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

Prototype

@Override
    public Context getApplicationContext() 

Source Link

Usage

From source file:com.blackcrowsteam.musicstop.NotificationHelper.java

/**
 * Show notification/* ww  w.ja  va  2s  . c  o  m*/
 * @param s Service
 * @param title title 
 * @param message message
 */
public void setMessage(Service s, CharSequence title, CharSequence message) {

    Context context = s.getApplicationContext();

    Intent notificationIntent = new Intent(context, StopActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notif = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(message)
            .setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher).setOngoing(true).setWhen(time)
            .build();

    // Pass the Notification to the NotificationManager:
    getManager(context).notify(id, notif);
    s.startForeground(id, notif);

}

From source file:com.nick.scalpel.core.AutoBindWirer.java

@Override
public void wire(Service service, Field field) {
    wire(service.getApplicationContext(), service, field);
}

From source file:org.aankor.animenforadio.RadioNotification.java

public RadioNotification(final Service s) {
    this.service = s;
    this.context = s.getApplicationContext();
    Intent main = new Intent(context, Main.class);
    main.setFlags(/*from  w  w w  .  j  a  va 2 s .  co m*/
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    init();

    builder = new NotificationCompat.Builder(context)
            .setContentIntent(PendingIntent.getActivity(context, 0, main, 0)).setTicker("AnimeNfo Radio Player")
            .setSmallIcon(R.drawable.ic_launcher).setOngoing(true);
}

From source file:org.broeuschmeul.android.gps.usb.provider.driver.USBGpsManager.java

/**
 * @param callingService//from   w w  w .  j ava2  s .c  o  m
 * @param vendorId
 * @param productId
 * @param maxRetries
 */
public USBGpsManager(Service callingService, int vendorId, int productId, int maxRetries) {
    this.gpsVendorId = vendorId;
    this.gpsProductId = productId;
    this.callingService = callingService;
    this.maxConnectionRetries = maxRetries + 1;
    this.nbRetriesRemaining = maxConnectionRetries;
    this.appContext = callingService.getApplicationContext();
    this.parser = new NmeaParser(10f, this.appContext);

    locationManager = (LocationManager) callingService.getSystemService(Context.LOCATION_SERVICE);

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(callingService);

    deviceSpeed = sharedPreferences.getString(USBGpsProviderService.PREF_GPS_DEVICE_SPEED,
            callingService.getString(R.string.defaultGpsDeviceSpeed));

    shouldSetTime = sharedPreferences.getBoolean(USBGpsProviderService.PREF_SET_TIME, false);
    timeSetAlready = true;

    defaultDeviceSpeed = callingService.getString(R.string.defaultGpsDeviceSpeed);
    setDeviceSpeed = !deviceSpeed.equals(callingService.getString(R.string.autoGpsDeviceSpeed));
    sirfGps = sharedPreferences.getBoolean(USBGpsProviderService.PREF_SIRF_GPS, false);
    notificationManager = (NotificationManager) callingService.getSystemService(Context.NOTIFICATION_SERVICE);
    parser.setLocationManager(locationManager);

    Intent stopIntent = new Intent(USBGpsProviderService.ACTION_STOP_GPS_PROVIDER);

    PendingIntent stopPendingIntent = PendingIntent.getService(appContext, 0, stopIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    connectionProblemNotificationBuilder = new NotificationCompat.Builder(appContext)
            .setContentIntent(stopPendingIntent).setSmallIcon(R.drawable.ic_stat_notify);

    Intent restartIntent = new Intent(USBGpsProviderService.ACTION_START_GPS_PROVIDER);
    PendingIntent restartPendingIntent = PendingIntent.getService(appContext, 0, restartIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    serviceStoppedNotificationBuilder = new NotificationCompat.Builder(appContext)
            .setContentIntent(restartPendingIntent).setSmallIcon(R.drawable.ic_stat_notify)
            .setContentTitle(
                    appContext.getString(R.string.service_closed_because_connection_problem_notification_title))
            .setContentText(
                    appContext.getString(R.string.service_closed_because_connection_problem_notification));

    usbManager = (UsbManager) callingService.getSystemService(Service.USB_SERVICE);

}