# Legal information
## Weather Information
**Weather Information** is licensed under the Apache License, Version 2.0. The full text
of the license can be found in:
- LICENSE
This license applies...
If you think the Android project AndroidWeatherInformation 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
/**
* Copyright 2014 Gustavo Martin Morcuende
*/*www.java2s.com*/
* 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 name.gumartinm.weather.information.boot;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import name.gumartinm.weather.information.R;
import name.gumartinm.weather.information.notification.NotificationIntentService;
publicclass BootReceiver extends BroadcastReceiver {
@Override
publicvoid onReceive(final Context context, final Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
// Update Time Rate
final SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
final String keyPreference = context
.getString(R.string.weather_preferences_update_time_rate_key);
final String updateTimeRate = sharedPreferences.getString(keyPreference, "");
long chosenInterval = 0;
if (updateTimeRate.equals(context.getString(R.string.update_time_rate_900))) {
chosenInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
} elseif (updateTimeRate.equals(context.getString(R.string.update_time_rate_1800))) {
chosenInterval = AlarmManager.INTERVAL_HALF_HOUR;
} elseif (updateTimeRate.equals(context.getString(R.string.update_time_rate_3600))) {
chosenInterval = AlarmManager.INTERVAL_HOUR;
} elseif (updateTimeRate.equals(context.getString(R.string.update_time_rate_43200))) {
chosenInterval = AlarmManager.INTERVAL_HALF_DAY;
} elseif (updateTimeRate.equals(context.getString(R.string.update_time_rate_86400))) {
chosenInterval = AlarmManager.INTERVAL_DAY;
}
if (chosenInterval != 0) {
final AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
final Intent serviceIntent = new Intent(context, NotificationIntentService.class);
final PendingIntent alarmIntent = PendingIntent.getService(
context,
0,
serviceIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
alarmMgr.setInexactRepeating(
AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + chosenInterval,
chosenInterval,
alarmIntent);
}
}
}
}