List of usage examples for android.content Context sendBroadcast
public abstract void sendBroadcast(@RequiresPermission Intent intent);
From source file:Main.java
public static void notifyMetaChanged(Context ctx, long id, String artist, String album, String track, int listSize, long duration, long position) { Intent i = new Intent(AVRCP_META_CHANGED); i.putExtra(KEY_ID, id);// w ww . ja v a 2s . c o m i.putExtra(KEY_ARTIST, artist); i.putExtra(KEY_ALBUM, album); i.putExtra(KEY_TRACK, track); i.putExtra(KEY_LIST_SIZE, listSize); i.putExtra(KEY_DURATION, duration); i.putExtra(KEY_POSITION, position); ctx.sendBroadcast(i); }
From source file:Main.java
private static void setBadgeSamsung(Context context, int count) { String launcherClassName = getLauncherClassName(context); if (launcherClassName == null) { return;//from w ww. j ava2 s.c om } Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE"); intent.putExtra("badge_count", count); intent.putExtra("badge_count_package_name", context.getPackageName()); intent.putExtra("badge_count_class_name", launcherClassName); context.sendBroadcast(intent); }
From source file:Main.java
public static void sendIconCountMessage(Context mContext, int num) { Intent i = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE"); i.putExtra("android.intent.extra.update_application_component_name", "com.xiaomi.alertsystem/.ui.LogoActivity"); String s = ""; if (num > 0) { if (num > 99) s = "99+"; else// w w w. j av a 2 s. c o m s = "" + num; i.putExtra("android.intent.extra.update_application_message_text", s); } mContext.sendBroadcast(i); }
From source file:Main.java
public static void installLaunchShortCut(Context context, Intent intent, String shortCutName, Bitmap icon, boolean duplicate) { Intent shortCutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName); shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); shortCutIntent.putExtra("duplicate", duplicate); intent.setAction(Intent.ACTION_MAIN); shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); context.sendBroadcast(shortCutIntent); }
From source file:Main.java
public static void createShortcut(Context ctx, String shortCutName, int iconId, Intent presentIntent) { Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); shortcutIntent.putExtra("duplicate", false); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(ctx, iconId)); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, presentIntent); ctx.sendBroadcast(shortcutIntent); }
From source file:com.commonsware.android.broadcast.fanout.MainActivity.java
private static void sendImplicitBroadcast(Context ctxt, Intent i) { PackageManager pm = ctxt.getPackageManager(); List<ResolveInfo> matches = pm.queryBroadcastReceivers(i, 0); for (ResolveInfo resolveInfo : matches) { Intent explicit = new Intent(i); ComponentName cn = new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName, resolveInfo.activityInfo.name); explicit.setComponent(cn);/*from w w w. j a v a2s . co m*/ ctxt.sendBroadcast(explicit); } }
From source file:net.henryco.opalette.api.utils.Utils.java
public static File updGallery(File outputFile, Context activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { final Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); final Uri contentUri = Uri.fromFile(outputFile); scanIntent.setData(contentUri);//from ww w . j a v a 2 s .com activity.sendBroadcast(scanIntent); } else activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); return outputFile; }
From source file:com.klinker.deskclock.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).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);//from w w w.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:org.isoron.uhabits.MainActivity.java
private static void updateWidgets(Context context, Class providerClass) { ComponentName provider = new ComponentName(context, providerClass); Intent intent = new Intent(context, providerClass); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); int ids[] = AppWidgetManager.getInstance(context).getAppWidgetIds(provider); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); context.sendBroadcast(intent); }
From source file:com.deepak.myclock.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).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.j a va2s .com*/ // 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()); }