@Override public void onCreate() { mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); // show the icon in the status bar showNotification(); // Start up the thread running the service. Note that we create a // separate thread because the service normally runs in the process's // main thread, which we don't want to block. Thread thr = new Thread(null, mTask, "AlarmService_Service"); thr.start(); }
public void run() { // Normally we would do some work here... for our sample, we will // just sleep for 30 seconds. long endTime = System.currentTimeMillis() + 15*1000; while (System.currentTimeMillis() < endTime) { synchronized (mBinder) { try { mBinder.wait(endTime - System.currentTimeMillis()); } catch (Exception e) { } } } // Done with our work... stop the service! AlarmService_Service.this.stopSelf(); } };
/** * Show a notification while this service is running. */ private void showNotification() { // In this sample, we'll use the same text for the ticker and the expanded notification CharSequence text = getText(R.string.alarm_service_started); // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.stat_sample, text, System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, AlarmService.class), 0); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, getText(R.string.alarm_service_label), text, contentIntent); // Send the notification. // We use a layout id because it is a unique number. We use it later to cancel. mNM.notify(R.string.alarm_service_started, notification); }
/** * Show a notification while this service is running. */ private void showNotification() { // In this sample, we'll use the same text for the ticker and the expanded notification CharSequence text = getText(R.string.alarm_service_started); // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, AlarmService.class), 0); // Set the info for the views that show in the notification panel. Notification notification = new Notification.Builder(this) .setSmallIcon(R.drawable.stat_sample) // the status icon .setTicker(text) // the status text .setWhen(System.currentTimeMillis()) // the time stamp .setContentTitle(getText(R.string.alarm_service_label)) // the label of the entry .setContentText(text) // the contents of the entry .setContentIntent(contentIntent) // The intent to send when the entry is clicked .build(); // Send the notification. // We use a layout id because it is a unique number. We use it later to cancel. mNM.notify(R.string.alarm_service_started, notification); }
@Override public void onCreate() { mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); // show the icon in the status bar showNotification(); // Start up the thread running the service. Note that we create a // separate thread because the service normally runs in the process's // main thread, which we don't want to block. Thread thr = new Thread(null, mTask, "AlarmService_Service"); thr.start(); }
public void run() { // Normally we would do some work here... for our sample, we will // just sleep for 30 seconds. long endTime = System.currentTimeMillis() + 15*1000; while (System.currentTimeMillis() < endTime) { synchronized (mBinder) { try { mBinder.wait(endTime - System.currentTimeMillis()); } catch (Exception e) { } } } // Done with our work... stop the service! AlarmService_Service.this.stopSelf(); } };