List of usage examples for android.content Context sendBroadcast
public abstract void sendBroadcast(@RequiresPermission Intent intent);
From source file:com.mods.grx.settings.utils.Utils.java
public static void send_bc1(Context context) { Intent intent = new Intent(); try {//from ww w .j a v a 2 s .c o m intent.setAction(context.getResources().getString(R.string.gs_grxBc1)); context.sendBroadcast(intent); } catch (Exception e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show(); } }
From source file:uk.ac.ucl.excites.sapelli.util.DeviceControl.java
/** * Set AirplaneMode//from www. j ava2 s. c o m * * @param context * @param enabled * (True to set the device in Airplane Mode) */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @SuppressWarnings("deprecation") private static void setAirplaneMode(Context context, boolean enabled) { try { // If airplane mode is on, value 0, else value is 1 if (canToogleAirplaneMode()) { Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, enabled ? 1 : 0); // Reload when the mode is changed each time by sending Intent Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state", enabled); context.sendBroadcast(intent); Debug.d("Airplane mode is: " + (enabled ? "ON" : "OFF")); } } catch (Exception e) { Debug.e("Error upon toggling airplane more.", e); } }
From source file:at.jclehner.rxdroid.NotificationReceiver.java
static void rescheduleAlarmsAndUpdateNotification(Context context, boolean silent) { if (context == null) context = RxDroid.getContext();/*ww w . ja va2s .c o m*/ final Intent intent = new Intent(context, NotificationReceiver.class); intent.setAction(Intent.ACTION_MAIN); intent.putExtra(NotificationReceiver.EXTRA_SILENT, silent); context.sendBroadcast(intent); }
From source file:com.adguard.android.service.FilterServiceImpl.java
public static void enableContentBlocker(Context context) { Intent intent = new Intent(); intent.setAction("com.samsung.android.sbrowser.contentBlocker.ACTION_UPDATE"); intent.setData(Uri.parse("package:com.adguard.android.contentblocker")); context.sendBroadcast(intent); }
From source file:Main.java
public static <T extends BroadcastReceiver> void scheduleUpdate(Context context, Class<T> clazz) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, clazz); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Random random = new Random(System.currentTimeMillis()); long offset = random.nextLong() % (12 * 60 * 60 * 1000); long interval = (24 * 60 * 60 * 1000) + offset; String prefKey = "pref_scheduled_monitor_config_update_" + clazz.getCanonicalName(); long scheduledTime = preferences.getLong(prefKey, -1); if (scheduledTime == -1) { context.sendBroadcast(intent); }//w ww. j av a2 s . c o m if (scheduledTime <= System.currentTimeMillis()) { context.sendBroadcast(intent); scheduledTime = System.currentTimeMillis() + interval; preferences.edit().putLong(prefKey, scheduledTime).commit(); Log.w("PeriodicActionUtils", "Scheduling for all new time: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); } else { Log.w("PeriodicActionUtils", "Scheduling for time found in preferences: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); } am.cancel(sender); am.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender); Log.w("PeriodicActionUtils", "Scheduled for: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); }
From source file:org.adblockplus.android.Utils.java
protected static void updateSubscriptionStatus(final Context context, final Subscription sub) { final JsValue jsDownloadStatus = sub.getProperty("downloadStatus"); final String downloadStatus = jsDownloadStatus.isNull() ? "" : jsDownloadStatus.toString(); final long lastDownload = sub.getProperty("lastDownload").asLong(); String status = "synchronize_never"; long time = 0; if (sub.isUpdating()) { status = "synchronize_in_progress"; } else if (StringUtils.isNotEmpty(downloadStatus) && !downloadStatus.equals("synchronize_ok")) { status = downloadStatus;/* w w w . j a v a 2s.co m*/ } else if (lastDownload > 0) { time = lastDownload; status = "synchronize_last_at"; } context.sendBroadcast(new Intent(AdblockPlus.BROADCAST_SUBSCRIPTION_STATUS) .putExtra("url", sub.getProperty("url").toString()).putExtra("status", status) .putExtra("time", time * 1000L)); }
From source file:org.ohmage.reminders.notif.Notifier.java
private static void handleNotifClicked(Context context, ArrayList<String> surveys) { //Hide the notification window when the user clicks on it hideNotification(context);//w w w . ja v a 2 s .co m //Broadcast to Ohmage Intent i = new Intent(ACTION_TRIGGER_NOTIFICATION); i.putExtra(EXTRA_SURVEYS, surveys); i.setPackage(context.getPackageName()); context.sendBroadcast(i); }
From source file:uk.ac.ucl.excites.sapelli.shared.util.android.DeviceControl.java
/** * Set AirplaneMode/*from ww w . j a v a2 s.c o m*/ * * @param context * @param enabled pass {@code true} to put the device in airplane mode, and {@code false} to leave airplane mode */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @SuppressWarnings("deprecation") private static void setAirplaneMode(Context context, boolean enabled) { try { // If airplane mode is on, value 0, else value is 1 if (canSetAirplaneMode()) { Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, enabled ? 1 : 0); // Reload when the mode is changed each time by sending Intent Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state", enabled); context.sendBroadcast(intent); Debug.d("Airplane mode is: " + (enabled ? "ON" : "OFF")); } } catch (Exception e) { Debug.e("Error upon toggling airplane more.", e); } }
From source file:com.deepak.myclock.alarms.AlarmNotifications.java
public static void broadcastNextAlarm(Context context, AlarmInstance instance) { String timeString = ""; boolean showStatusIcon = false; if (instance != null) { timeString = AlarmUtils.getFormattedTime(context, instance.getAlarmTime()); showStatusIcon = true;/* w w w . ja v a 2s. c o m*/ } // Set and notify next alarm text to system Log.i("Displaying next alarm time: \'" + timeString + '\''); Settings.System.putString(context.getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED, timeString); Intent alarmChanged = new Intent(SYSTEM_ALARM_CHANGE_ACTION); alarmChanged.putExtra("alarmSet", showStatusIcon); context.sendBroadcast(alarmChanged); }
From source file:se.oort.clockify.alarms.AlarmNotifications.java
public static void broadcastNextAlarm(Context context, AlarmInstance instance) { String timeString = ""; boolean showStatusIcon = false; if (instance != null) { timeString = AlarmUtils.getFormattedTime(context, instance.getAlarmTime()); showStatusIcon = true;//from w w w . ja v a 2s . c o m } // Set and notify next alarm text to system Log.i(LOG_TAG, "Displaying next alarm time: \'" + timeString + '\''); Settings.System.putString(context.getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED, timeString); Intent alarmChanged = new Intent(SYSTEM_ALARM_CHANGE_ACTION); alarmChanged.putExtra("alarmSet", showStatusIcon); context.sendBroadcast(alarmChanged); }