Android Open Source - watchme Notification Service






From Project

Back to project page watchme.

License

The source code is released under:

Copyright (c) 2012 Johan Brook, Robin Andersson, Lisa Stenberg, Mattias Henriksson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documen...

If you think the Android project watchme listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
*  NotificationService.java/*ww  w  .  j  av  a 2 s  .  co  m*/
*
*  The service class which provides a server functionality for
*  clients to connect to.
*
*  @author Johan
*  @copyright (c) 2012 Johan Brook, Robin Andersson, Lisa Stenberg, Mattias Henriksson
*  @license MIT
*/

package se.chalmers.watchme.notifications;

import java.io.Serializable;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class NotificationService extends Service {
  
  private final IBinder binder = new ServiceBinder();

  /**
   * Embedded Binder class which provides a reference
   * to this service. 
   * 
   * @author Johan
   */
  public class ServiceBinder extends Binder {
    public NotificationService getService() {
      return NotificationService.this;
    }
  }

  @Override
  public IBinder onBind(Intent arg0) {
    return this.binder;
  }
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startID) {
    Log.i("Custom", "Received start id " + startID + ": " + intent);
        
    // This service is sticky - it runs until it's stopped.
    return START_STICKY;
  }
  
  /**
   * Set a new alarm task for a movie.
   * 
   * <p>The task is started on a separate thread.</p>
   * 
   * @param movie The movie
   */
  public void setAlarmTaskForMovie(final Notifiable movie) {
    Log.i("Custom", "Set alarm");
    
    final AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    
    // Start a new task for the alarm on another thread (separated from the UI thread)
    (new Runnable() {
      
      public void run() {
        Log.i("Custom", "Run alarm task");
        // Create a new intent to send to the NotifyService class
        Intent intent = new Intent(NotificationService.this, NotifyService.class);

        // Add extra data
        intent.putExtra(NotifyService.INTENT_NOTIFY, true);
        intent.putExtra(NotifyService.INTENT_MOVIE, (Serializable) movie);
        
        PendingIntent pending = PendingIntent.getService(NotificationService.this, 0, intent, 0);
        
        // Set the alarm, along with the pending intent to call when triggered
        manager.set(AlarmManager.RTC, movie.getDateInMilliSeconds(), pending);
      }
    }).run();
  }
}




Java Source Code List

se.chalmers.watchme.activity.AddMovieActivity.java
se.chalmers.watchme.activity.AutoCompleteAdapter.java
se.chalmers.watchme.activity.MainActivity.java
se.chalmers.watchme.activity.MovieDetailsActivity.java
se.chalmers.watchme.activity.SearchableActivity.java
se.chalmers.watchme.activity.TabsAdapter.java
se.chalmers.watchme.activity.TagMovieListActivity.java
se.chalmers.watchme.database.DatabaseAdapter.java
se.chalmers.watchme.database.DatabaseHelper.java
se.chalmers.watchme.database.GenericCursorLoader.java
se.chalmers.watchme.database.HasTagTable.java
se.chalmers.watchme.database.ICursorHelper.java
se.chalmers.watchme.database.MovieAlreadyExistsException.java
se.chalmers.watchme.database.MoviesTable.java
se.chalmers.watchme.database.TagsTable.java
se.chalmers.watchme.database.WatchMeContentProvider.java
se.chalmers.watchme.model.Movie.java
se.chalmers.watchme.model.Tag.java
se.chalmers.watchme.net.HttpRetriever.java
se.chalmers.watchme.net.IMDBHandler.java
se.chalmers.watchme.net.ImageDownloadTask.java
se.chalmers.watchme.net.MovieSource.java
se.chalmers.watchme.net.NoEntityException.java
se.chalmers.watchme.notifications.Notifiable.java
se.chalmers.watchme.notifications.NotificationClient.java
se.chalmers.watchme.notifications.NotificationService.java
se.chalmers.watchme.notifications.NotifyService.java
se.chalmers.watchme.ui.ContentListFragment.java
se.chalmers.watchme.ui.DatePickerFragment.java
se.chalmers.watchme.ui.ImageDialog.java
se.chalmers.watchme.ui.MovieListFragment.java
se.chalmers.watchme.ui.TagListFragment.java
se.chalmers.watchme.utils.DateTimeUtils.java
se.chalmers.watchme.utils.ImageCache.java
se.chalmers.watchme.utils.MenuUtils.java
se.chalmers.watchme.utils.MovieHelper.java
se.chalmers.watchmetest.Constants.java
se.chalmers.watchmetest.activity.MainActivityTest.java
se.chalmers.watchmetest.activity.MovieDetailsActivityTest.java
se.chalmers.watchmetest.activity.SearchableActivityTest.java
se.chalmers.watchmetest.activity.TabsAdapterTest.java
se.chalmers.watchmetest.activity.TagMovieListActivityTest.java
se.chalmers.watchmetest.database.WatchMeContentProviderTest.java
se.chalmers.watchmetest.model.MovieTest.java
se.chalmers.watchmetest.model.TagTest.java
se.chalmers.watchmetest.net.HttpRetrieverTest.java
se.chalmers.watchmetest.net.IMDBHandlerTest.java
se.chalmers.watchmetest.ui.MovieListFragmentTest.java
se.chalmers.watchmetest.ui.TagListFragmentTest.java
se.chalmers.watchmetest.util.DateTimeUtilsTest.java
se.chalmers.watchmetest.util.MovieHelperTest.java