List of usage examples for android.content Context sendBroadcast
public abstract void sendBroadcast(@RequiresPermission Intent intent);
From source file:Main.java
public static void setAirplaneMode(Context context, boolean newStatus) { boolean airplaneModeOn = isAirplaneModeOn(context); if (airplaneModeOn && newStatus) { return;//from w ww.ja va 2 s. co m } if (!airplaneModeOn && !newStatus) { return; } if (airplaneModeOn && !newStatus) { Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0); Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state", 0); context.sendBroadcast(intent); return; } if (!airplaneModeOn && newStatus) { Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 1); Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state", 1); context.sendBroadcast(intent); return; } }
From source file:org.jitsi.android.gui.DialogActivity.java
/** * Fires {@link #ACTION_CLOSE_DIALOG} brodcast action in order to close * the dialog identified by given <tt>dialogId</tt>. * @param ctx the context.//from www. j a v a2s .c o m * @param dialogId dialog identifier returned when the dialog was created. */ public static void closeDialog(Context ctx, long dialogId) { Intent intent = new Intent(ACTION_CLOSE_DIALOG); intent.putExtra(EXTRA_DIALOG_ID, dialogId); ctx.sendBroadcast(intent); }
From source file:se.oort.clockify.alarms.AlarmNotifications.java
public static void showAlarmNotification(Context context, AlarmInstance instance) { Log.v(LOG_TAG, "Displaying alarm notification for alarm instance: " + instance.mId); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Close dialogs and window shade, so this will display context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); Resources resources = context.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(AlarmUtils.getFormattedTime(context, instance.getAlarmTime())) .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false).setWhen(0); // Setup Snooze Action Intent snoozeIntent = AlarmStateManager.createStateChangeIntent(context, "SNOOZE_TAG", instance, AlarmInstance.SNOOZE_STATE); PendingIntent snoozePendingIntent = PendingIntent.getBroadcast(context, instance.hashCode(), snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.stat_notify_alarm, resources.getString(R.string.alarm_alert_snooze_text), snoozePendingIntent);/*w ww .java 2 s. co m*/ // Setup Dismiss Action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance, AlarmInstance.DISMISSED_STATE); PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(android.R.drawable.ic_menu_close_clear_cancel, resources.getString(R.string.alarm_alert_dismiss_text), dismissPendingIntent); // Setup Content Action Intent contentIntent = AlarmInstance.createIntent(context, AlarmActivity.class, instance.mId); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), contentIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup fullscreen intent Intent fullScreenIntent = AlarmInstance.createIntent(context, AlarmActivity.class, instance.mId); // set action, so we can be different then content pending intent fullScreenIntent.setAction("fullscreen_activity"); fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); notification.setFullScreenIntent(PendingIntent.getActivity(context, instance.hashCode(), fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT), true); notification.setPriority(NotificationCompat.PRIORITY_MAX); nm.cancel(instance.hashCode()); nm.notify(instance.hashCode(), notification.build()); }
From source file:com.embeddedlog.LightUpDroid.alarms.AlarmNotifications.java
public static void showAlarmNotification(Context context, AlarmInstance instance) { Log.v("Displaying alarm notification for alarm instance: " + instance.mId); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Close dialogs and window shade, so this will display context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); Resources resources = context.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(AlarmUtils.getFormattedTime(context, instance.getAlarmTime())) .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false) .setDefaults(NotificationCompat.DEFAULT_LIGHTS).setWhen(0) .setCategory(NotificationCompat.CATEGORY_ALARM); // Setup Snooze Action Intent snoozeIntent = AlarmStateManager.createStateChangeIntent(context, "SNOOZE_TAG", instance, AlarmInstance.SNOOZE_STATE); PendingIntent snoozePendingIntent = PendingIntent.getBroadcast(context, instance.hashCode(), snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.stat_notify_alarm, resources.getString(R.string.alarm_alert_snooze_text), snoozePendingIntent);// w w w .j av a2s .co m // Setup Dismiss Action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance, AlarmInstance.DISMISSED_STATE); PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(android.R.drawable.ic_menu_close_clear_cancel, resources.getString(R.string.alarm_alert_dismiss_text), dismissPendingIntent); // Setup Content Action Intent contentIntent = AlarmInstance.createIntent(context, AlarmActivity.class, instance.mId); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), contentIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup fullscreen intent Intent fullScreenIntent = AlarmInstance.createIntent(context, AlarmActivity.class, instance.mId); // set action, so we can be different then content pending intent fullScreenIntent.setAction("fullscreen_activity"); fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); notification.setFullScreenIntent(PendingIntent.getActivity(context, instance.hashCode(), fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT), true); notification.setPriority(NotificationCompat.PRIORITY_MAX); nm.cancel(instance.hashCode()); nm.notify(instance.hashCode(), notification.build()); }
From source file:cw.kop.autobackground.files.FileHandler.java
public static void cancel(Context appContext) { if (downloadThread != null) { downloadThread.interrupt();//ww w . j ava 2s .com Toast.makeText(appContext, "Stopping download...", Toast.LENGTH_SHORT).show(); Intent closeDrawer = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); appContext.sendBroadcast(closeDrawer); Intent resetDownloadIntent = new Intent(FileHandler.DOWNLOAD_TERMINATED); LocalBroadcastManager.getInstance(appContext).sendBroadcast(resetDownloadIntent); } isDownloading = false; }
From source file:Main.java
public static void createShortcut(Context context, String shortcutName, int drawableResId, Intent shortcutIntent) {//from w w w . j a va 2 s . c o m Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); shortcutintent.putExtra("duplicate", false); shortcutintent.putExtra("android.intent.extra.shortcut.NAME", shortcutName); shortcutintent.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(context, drawableResId)); shortcutintent.putExtra("android.intent.extra.shortcut.INTENT", shortcutIntent); context.sendBroadcast(shortcutintent); }
From source file:com.airbop.library.simple.CommonUtilities.java
static void onGCMMessage(Context context, Bundle bundle) { Intent intent = new Intent(GCM_MESSAGE_ACTION); intent.putExtras(bundle);/*from ww w. j a v a 2s.co m*/ String packageName = context.getPackageName(); intent.setPackage(packageName); //sendLocalBroadcast(context, intent); context.sendBroadcast(intent); }
From source file:com.liato.bankdroid.appwidget.AutoRefreshService.java
public static void broadcastTransactionUpdate(final Context context, final long bankId, final String accountId) { final Intent i = new Intent(BROADCAST_TRANSACTIONS_UPDATED); i.putExtra("accountId", Long.toString(bankId) + "_" + accountId); context.sendBroadcast(i); }
From source file:Main.java
public static void samsungShortCut(Context context, String num) { int numInt = Integer.valueOf(num); if (numInt < 1) { num = "0"; } else if (numInt > 99) { num = "99"; }/* ww w . jav a 2s . co m*/ String activityName = getLaunchActivityName(context); Intent localIntent = new Intent("android.intent.action.BADGE_COUNT_UPDATE"); localIntent.putExtra("badge_count", Integer.parseInt(num)); localIntent.putExtra("badge_count_package_name", context.getPackageName()); localIntent.putExtra("badge_count_class_name", activityName); context.sendBroadcast(localIntent); }
From source file:eu.power_switch.widget.provider.ReceiverWidgetProvider.java
/** * Forces an Update of all Receiver Widgets * * @param context any suitable context//from w ww . j a va 2 s . c o m */ public static void forceWidgetUpdate(Context context) { // update receiver widgets Intent intent = new Intent(context, ReceiverWidgetProvider.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); int ids[] = AppWidgetManager.getInstance(context.getApplicationContext()) .getAppWidgetIds(new ComponentName(context.getApplicationContext(), ReceiverWidgetProvider.class)); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); context.sendBroadcast(intent); }