diff options
author | Alexander Lucas <alexlucas@google.com> | 2014-08-11 12:38:34 -0700 |
---|---|---|
committer | Trevor Johns <trevorjohns@google.com> | 2014-09-05 19:41:36 +0000 |
commit | 54d23241d5c140a5887e26431d5d81b302b3e539 (patch) | |
tree | 5d139231d80ba3dd4c7996a43fdbb7a4701f6faf /background | |
parent | 33cef3fa89217b4cd159c1eab2de4d2a136796f4 (diff) | |
download | android-54d23241d5c140a5887e26431d5d81b302b3e539.tar.gz |
Per b/11465024, deleting Scheduler legacy project.
Change-Id: Idf08db96a96cbae7a459ab313eb90509c54e286b
(cherry picked from commit 1236c977481b365b27255cac903e9caa6ea3be1c)
Diffstat (limited to 'background')
16 files changed, 0 insertions, 615 deletions
diff --git a/background/alarms/Scheduler/AndroidManifest.xml b/background/alarms/Scheduler/AndroidManifest.xml deleted file mode 100755 index 1e43d637..00000000 --- a/background/alarms/Scheduler/AndroidManifest.xml +++ /dev/null @@ -1,52 +0,0 @@ -<!-- - Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.android.scheduler" - android:versionCode="1" - android:versionName="1.0"> - - <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="18" /> - <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission> - <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> - <uses-permission android:name="android.permission.INTERNET" /> - - <application android:label="@string/app_name" - android:icon="@drawable/ic_launcher" - android:theme="@style/Theme.Sample"> - - <activity android:name=".MainActivity" - android:label="@string/app_name" - android:uiOptions="splitActionBarWhenNarrow"> - - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - - <receiver android:name=".SampleAlarmReceiver"></receiver> - - <receiver android:name=".SampleBootReceiver" - android:enabled="false"> - <intent-filter> - <action android:name="android.intent.action.BOOT_COMPLETED"></action> - </intent-filter> - </receiver> - <service android:name=".SampleSchedulingService" /> - </application> - -</manifest> diff --git a/background/alarms/Scheduler/res/drawable-hdpi/ic_launcher.png b/background/alarms/Scheduler/res/drawable-hdpi/ic_launcher.png Binary files differdeleted file mode 100644 index 015d2486..00000000 --- a/background/alarms/Scheduler/res/drawable-hdpi/ic_launcher.png +++ /dev/null diff --git a/background/alarms/Scheduler/res/drawable-mdpi/ic_launcher.png b/background/alarms/Scheduler/res/drawable-mdpi/ic_launcher.png Binary files differdeleted file mode 100644 index 605a2565..00000000 --- a/background/alarms/Scheduler/res/drawable-mdpi/ic_launcher.png +++ /dev/null diff --git a/background/alarms/Scheduler/res/drawable-xhdpi/ic_launcher.png b/background/alarms/Scheduler/res/drawable-xhdpi/ic_launcher.png Binary files differdeleted file mode 100644 index c08bafa5..00000000 --- a/background/alarms/Scheduler/res/drawable-xhdpi/ic_launcher.png +++ /dev/null diff --git a/background/alarms/Scheduler/res/drawable-xxhdpi/ic_launcher.png b/background/alarms/Scheduler/res/drawable-xxhdpi/ic_launcher.png Binary files differdeleted file mode 100644 index 1224b391..00000000 --- a/background/alarms/Scheduler/res/drawable-xxhdpi/ic_launcher.png +++ /dev/null diff --git a/background/alarms/Scheduler/res/layout/activity_main.xml b/background/alarms/Scheduler/res/layout/activity_main.xml deleted file mode 100755 index 8ba99cd6..00000000 --- a/background/alarms/Scheduler/res/layout/activity_main.xml +++ /dev/null @@ -1,27 +0,0 @@ -<!-- - Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent"> - - <TextView android:id="@+id/sample_output" - style="@style/Widget.SampleOutput" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:text="@string/intro_message" /> - -</ScrollView> diff --git a/background/alarms/Scheduler/res/menu/main.xml b/background/alarms/Scheduler/res/menu/main.xml deleted file mode 100644 index f961a640..00000000 --- a/background/alarms/Scheduler/res/menu/main.xml +++ /dev/null @@ -1,24 +0,0 @@ -<!-- - Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<menu xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:id="@+id/start_action" - android:showAsAction="ifRoom|withText" - android:title="@string/start_text" /> - <item android:id="@+id/cancel_action" - android:showAsAction="ifRoom|withText" - android:title="@string/cancel_text" /> -</menu> diff --git a/background/alarms/Scheduler/res/values-sw600dp/styles.xml b/background/alarms/Scheduler/res/values-sw600dp/styles.xml deleted file mode 100644 index ffcbe8ac..00000000 --- a/background/alarms/Scheduler/res/values-sw600dp/styles.xml +++ /dev/null @@ -1,28 +0,0 @@ -<!-- - Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<resources> - - <style name="Widget.SampleOutput"> - <item name="android:paddingTop">@dimen/margin_medium</item> - <item name="android:paddingBottom">@dimen/margin_medium</item> - <item name="android:paddingLeft">@dimen/margin_huge</item> - <item name="android:paddingRight">@dimen/margin_huge</item> - <item name="android:textAppearance">?android:textAppearanceLarge</item> - <item name="android:lineSpacingMultiplier">1.2</item> - </style> - -</resources> diff --git a/background/alarms/Scheduler/res/values-v11/styles.xml b/background/alarms/Scheduler/res/values-v11/styles.xml deleted file mode 100644 index c6c648b4..00000000 --- a/background/alarms/Scheduler/res/values-v11/styles.xml +++ /dev/null @@ -1,19 +0,0 @@ -<!-- - Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<resources> - <style name="Theme.Base" parent="android:Theme.Holo.Light" /> -</resources> diff --git a/background/alarms/Scheduler/res/values/dimens.xml b/background/alarms/Scheduler/res/values/dimens.xml deleted file mode 100644 index 952c2204..00000000 --- a/background/alarms/Scheduler/res/values/dimens.xml +++ /dev/null @@ -1,27 +0,0 @@ -<!-- - Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<resources> - - <!-- Define standard dimensions to comply with Holo-style grids and rhythm. --> - - <dimen name="margin_tiny">4dp</dimen> - <dimen name="margin_small">8dp</dimen> - <dimen name="margin_medium">16dp</dimen> - <dimen name="margin_large">32dp</dimen> - <dimen name="margin_huge">64dp</dimen> - -</resources> diff --git a/background/alarms/Scheduler/res/values/strings.xml b/background/alarms/Scheduler/res/values/strings.xml deleted file mode 100755 index 9caa7a82..00000000 --- a/background/alarms/Scheduler/res/values/strings.xml +++ /dev/null @@ -1,33 +0,0 @@ -<!-- - Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<resources> - <string name="app_name">Scheduler</string> - <string name="intro_message">Welcome to <b>Scheduler</b>! - This sample demonstrates how you can schedule an alarm that causes a service to - be started. This is useful when you want to schedule alarms that initiate - long-running operations. Click START ALARM to activate an alarm to check - the Google home page for a custom doodle once a day. If the app finds a doodle, - it posts a \"Doodle Alert\" as a notification. Click CANCEL ALARM to cancel the - alarm. Once the alarm is active, it automatically restarts when the device is - rebooted.</string> - <string name="start_text">Start Alarm</string> - <string name="cancel_text">Cancel Alarm</string> - <string name="doodle_alert">Doodle Alert</string> - <string name="doodle_found">There is a Google doodle today!!</string> - <string name="no_doodle">No Google doodle today.</string> - <string name="connection_error">Connection error.</string> -</resources> diff --git a/background/alarms/Scheduler/res/values/styles.xml b/background/alarms/Scheduler/res/values/styles.xml deleted file mode 100644 index b1461ddc..00000000 --- a/background/alarms/Scheduler/res/values/styles.xml +++ /dev/null @@ -1,35 +0,0 @@ -<!-- - Copyright 2013 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<resources> - - <!-- Activity themes --> - - <style name="Theme.Base" parent="android:Theme.Light" /> - - <style name="Theme.Sample" parent="Theme.Base" /> - - <!-- Widget styling --> - - <style name="Widget" /> - - <style name="Widget.SampleOutput"> - <item name="android:padding">@dimen/margin_medium</item> - <item name="android:textAppearance">?android:textAppearanceMedium</item> - <item name="android:lineSpacingMultiplier">1.1</item> - </style> - -</resources> diff --git a/background/alarms/Scheduler/src/com/example/android/scheduler/MainActivity.java b/background/alarms/Scheduler/src/com/example/android/scheduler/MainActivity.java deleted file mode 100755 index efb8e524..00000000 --- a/background/alarms/Scheduler/src/com/example/android/scheduler/MainActivity.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.scheduler; - -import android.app.Activity; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; - - -/** - * This sample demonstrates how to schedule an alarm that causes a service to - * be started. This is useful when you want to schedule alarms that initiate - * long-running operations, such as retrieving a daily forecast. - * This particular sample retrieves content from the Google home page once a day and - * checks it for the search string "doodle". If it finds this string, that indicates - * that the page contains a custom doodle instead of the standard Google logo. - */ -public class MainActivity extends Activity { - SampleAlarmReceiver alarm = new SampleAlarmReceiver(); - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.main, menu); - return true; - } - - // Menu options to set and cancel the alarm. - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - // When the user clicks START ALARM, set the alarm. - case R.id.start_action: - alarm.setAlarm(this); - return true; - // When the user clicks CANCEL ALARM, cancel the alarm. - case R.id.cancel_action: - alarm.cancelAlarm(this); - return true; - } - return false; - } -} diff --git a/background/alarms/Scheduler/src/com/example/android/scheduler/SampleAlarmReceiver.java b/background/alarms/Scheduler/src/com/example/android/scheduler/SampleAlarmReceiver.java deleted file mode 100644 index 3a8cce1c..00000000 --- a/background/alarms/Scheduler/src/com/example/android/scheduler/SampleAlarmReceiver.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.example.android.scheduler; - -import android.app.AlarmManager; -import android.app.PendingIntent; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.support.v4.content.WakefulBroadcastReceiver; - -import java.util.Calendar; - -/** - * When the alarm fires, this WakefulBroadcastReceiver receives the broadcast Intent - * and then starts the IntentService {@code SampleSchedulingService} to do some work. - */ -public class SampleAlarmReceiver extends WakefulBroadcastReceiver { - // The app's AlarmManager, which provides access to the system alarm services. - private AlarmManager alarmMgr; - - // The pending intent that is triggered when the alarm fires. - private PendingIntent alarmIntent; - - @Override - public void onReceive(Context context, Intent intent) { - // BEGIN_INCLUDE(alarm_onreceive) - /* - * If your receiver intent includes extras that need to be passed along to the - * service, use setComponent() to indicate that the service should handle the - * receiver's intent. For example: - * - * ComponentName comp = new ComponentName(context.getPackageName(), - * MyService.class.getName()); - * - * // This intent passed in this call will include the wake lock extra as well as - * // the receiver intent contents. - * startWakefulService(context, (intent.setComponent(comp))); - * - * In this example, we simply create a new intent to deliver to the service. - * This intent holds an extra identifying the wake lock. - */ - Intent service = new Intent(context, SampleSchedulingService.class); - - // Start the service, keeping the device awake while it is launching. - startWakefulService(context, service); - // END_INCLUDE(alarm_onreceive) - } - - // BEGIN_INCLUDE(set_alarm) - /** - * Sets a repeating alarm that runs once a day at approximately 8:30 a.m. When the - * alarm fires, the app broadcasts an Intent to this WakefulBroadcastReceiver. - * @param context - */ - public void setAlarm(Context context) { - alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); - Intent intent = new Intent(context, SampleAlarmReceiver.class); - alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); - - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - // Set the alarm's trigger time to 8:30 a.m. - calendar.set(Calendar.HOUR_OF_DAY, 8); - calendar.set(Calendar.MINUTE, 30); - - /* - * If you don't have precise time requirements, use an inexact repeating alarm - * to minimize the drain on the device battery. - * - * The call below specifies the alarm type, the trigger time, the interval at - * which the alarm is fired, and the alarm's associated PendingIntent. - * It uses the alarm type RTC_WAKEUP ("Real Time Clock" wake up), which wakes up - * the device and triggers the alarm according to the time of the device's clock. - * - * Alternatively, you can use the alarm type ELAPSED_REALTIME_WAKEUP to trigger - * an alarm based on how much time has elapsed since the device was booted. This - * is the preferred choice if your alarm is based on elapsed time--for example, if - * you simply want your alarm to fire every 60 minutes. You only need to use - * RTC_WAKEUP if you want your alarm to fire at a particular date/time. Remember - * that clock-based time may not translate well to other locales, and that your - * app's behavior could be affected by the user changing the device's time setting. - * - * Here are some examples of ELAPSED_REALTIME_WAKEUP: - * - * // Wake up the device to fire a one-time alarm in one minute. - * alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, - * SystemClock.elapsedRealtime() + - * 60*1000, alarmIntent); - * - * // Wake up the device to fire the alarm in 30 minutes, and every 30 minutes - * // after that. - * alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, - * AlarmManager.INTERVAL_HALF_HOUR, - * AlarmManager.INTERVAL_HALF_HOUR, alarmIntent); - */ - - // Set the alarm to fire at approximately 8:30 a.m., according to the device's - // clock, and to repeat once a day. - alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, - calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent); - - // Enable {@code SampleBootReceiver} to automatically restart the alarm when the - // device is rebooted. - ComponentName receiver = new ComponentName(context, SampleBootReceiver.class); - PackageManager pm = context.getPackageManager(); - - pm.setComponentEnabledSetting(receiver, - PackageManager.COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP); - } - // END_INCLUDE(set_alarm) - - /** - * Cancels the alarm. - * @param context - */ - // BEGIN_INCLUDE(cancel_alarm) - public void cancelAlarm(Context context) { - // If the alarm has been set, cancel it. - if (alarmMgr!= null) { - alarmMgr.cancel(alarmIntent); - } - - // Disable {@code SampleBootReceiver} so that it doesn't automatically restart the - // alarm when the device is rebooted. - ComponentName receiver = new ComponentName(context, SampleBootReceiver.class); - PackageManager pm = context.getPackageManager(); - - pm.setComponentEnabledSetting(receiver, - PackageManager.COMPONENT_ENABLED_STATE_DISABLED, - PackageManager.DONT_KILL_APP); - } - // END_INCLUDE(cancel_alarm) -} diff --git a/background/alarms/Scheduler/src/com/example/android/scheduler/SampleBootReceiver.java b/background/alarms/Scheduler/src/com/example/android/scheduler/SampleBootReceiver.java deleted file mode 100644 index 16464da9..00000000 --- a/background/alarms/Scheduler/src/com/example/android/scheduler/SampleBootReceiver.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.example.android.scheduler; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -/** - * This BroadcastReceiver automatically (re)starts the alarm when the device is - * rebooted. This receiver is set to be disabled (android:enabled="false") in the - * application's manifest file. When the user sets the alarm, the receiver is enabled. - * When the user cancels the alarm, the receiver is disabled, so that rebooting the - * device will not trigger this receiver. - */ -// BEGIN_INCLUDE(autostart) -public class SampleBootReceiver extends BroadcastReceiver { - SampleAlarmReceiver alarm = new SampleAlarmReceiver(); - @Override - public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) - { - alarm.setAlarm(context); - } - } -} -//END_INCLUDE(autostart) diff --git a/background/alarms/Scheduler/src/com/example/android/scheduler/SampleSchedulingService.java b/background/alarms/Scheduler/src/com/example/android/scheduler/SampleSchedulingService.java deleted file mode 100644 index d99fe0c5..00000000 --- a/background/alarms/Scheduler/src/com/example/android/scheduler/SampleSchedulingService.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.example.android.scheduler; - -import android.app.IntentService; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.support.v4.app.NotificationCompat; -import android.util.Log; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; - -/** - * This {@code IntentService} does the app's actual work. - * {@code SampleAlarmReceiver} (a {@code WakefulBroadcastReceiver}) holds a - * partial wake lock for this service while the service does its work. When the - * service is finished, it calls {@code completeWakefulIntent()} to release the - * wake lock. - */ -public class SampleSchedulingService extends IntentService { - public SampleSchedulingService() { - super("SchedulingService"); - } - - public static final String TAG = "Scheduling Demo"; - // An ID used to post the notification. - public static final int NOTIFICATION_ID = 1; - // The string the app searches for in the Google home page content. If the app finds - // the string, it indicates the presence of a doodle. - public static final String SEARCH_STRING = "doodle"; - // The Google home page URL from which the app fetches content. - // You can find a list of other Google domains with possible doodles here: - // http://en.wikipedia.org/wiki/List_of_Google_domains - public static final String URL = "http://www.google.com"; - private NotificationManager mNotificationManager; - NotificationCompat.Builder builder; - - @Override - protected void onHandleIntent(Intent intent) { - // BEGIN_INCLUDE(service_onhandle) - // The URL from which to fetch content. - String urlString = URL; - - String result =""; - - // Try to connect to the Google homepage and download content. - try { - result = loadFromNetwork(urlString); - } catch (IOException e) { - Log.i(TAG, getString(R.string.connection_error)); - } - - // If the app finds the string "doodle" in the Google home page content, it - // indicates the presence of a doodle. Post a "Doodle Alert" notification. - if (result.indexOf(SEARCH_STRING) != -1) { - sendNotification(getString(R.string.doodle_found)); - Log.i(TAG, "Found doodle!!"); - } else { - sendNotification(getString(R.string.no_doodle)); - Log.i(TAG, "No doodle found. :-("); - } - // Release the wake lock provided by the BroadcastReceiver. - SampleAlarmReceiver.completeWakefulIntent(intent); - // END_INCLUDE(service_onhandle) - } - - // Post a notification indicating whether a doodle was found. - private void sendNotification(String msg) { - mNotificationManager = (NotificationManager) - this.getSystemService(Context.NOTIFICATION_SERVICE); - - PendingIntent contentIntent = PendingIntent.getActivity(this, 0, - new Intent(this, MainActivity.class), 0); - - NotificationCompat.Builder mBuilder = - new NotificationCompat.Builder(this) - .setSmallIcon(R.drawable.ic_launcher) - .setContentTitle(getString(R.string.doodle_alert)) - .setStyle(new NotificationCompat.BigTextStyle() - .bigText(msg)) - .setContentText(msg); - - mBuilder.setContentIntent(contentIntent); - mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); - } - -// -// The methods below this line fetch content from the specified URL and return the -// content as a string. -// - /** Given a URL string, initiate a fetch operation. */ - private String loadFromNetwork(String urlString) throws IOException { - InputStream stream = null; - String str =""; - - try { - stream = downloadUrl(urlString); - str = readIt(stream); - } finally { - if (stream != null) { - stream.close(); - } - } - return str; - } - - /** - * Given a string representation of a URL, sets up a connection and gets - * an input stream. - * @param urlString A string representation of a URL. - * @return An InputStream retrieved from a successful HttpURLConnection. - * @throws IOException - */ - private InputStream downloadUrl(String urlString) throws IOException { - - URL url = new URL(urlString); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setReadTimeout(10000 /* milliseconds */); - conn.setConnectTimeout(15000 /* milliseconds */); - conn.setRequestMethod("GET"); - conn.setDoInput(true); - // Start the query - conn.connect(); - InputStream stream = conn.getInputStream(); - return stream; - } - - /** - * Reads an InputStream and converts it to a String. - * @param stream InputStream containing HTML from www.google.com. - * @return String version of InputStream. - * @throws IOException - */ - private String readIt(InputStream stream) throws IOException { - - StringBuilder builder = new StringBuilder(); - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - for(String line = reader.readLine(); line != null; line = reader.readLine()) - builder.append(line); - reader.close(); - return builder.toString(); - } -} |