List of usage examples for android.content Context sendBroadcast
public abstract void sendBroadcast(@RequiresPermission Intent intent);
From source file:Main.java
public static void notifyFileSystemChanged(String path, Context mContext) { if (path == null) return;//w ww. ja va2 s. c o m final File f = new File(path); final Intent intent; if (f.isDirectory()) { intent = new Intent(Intent.ACTION_MEDIA_MOUNTED); intent.setClassName("com.android.providers.media", "com.android.providers.media.MediaScannerReceiver"); intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory())); } else { intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setData(Uri.fromFile(new File(path))); } mContext.sendBroadcast(intent); }
From source file:com.gaba.alex.trafficincidents.Utility.java
public static void updateWidget(Context context) { Intent intent = new Intent(context, IncidentsWidgetProvider.class); intent.setAction("android.appwidget.action.APPWIDGET_UPDATE"); ComponentName name = new ComponentName(context, IncidentsWidgetProvider.class); int[] ids = AppWidgetManager.getInstance(context).getAppWidgetIds(name); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); context.sendBroadcast(intent); }
From source file:Main.java
public static boolean insertMediaStore(Context context, File file, String imageName) { if (context == null || file == null || !file.exists()) { return false; }//w w w .j a v a 2s.co m if (TextUtils.isEmpty(imageName)) { imageName = SystemClock.currentThreadTimeMillis() + PNG; } try { MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), imageName, null); // String imagePath = // MediaStore.Images.Media.insertImage(getContentResolver(), // bitmap, "", ""); context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file))); } catch (FileNotFoundException e) { e.printStackTrace(); return false; } return true; }
From source file:me.zhang.bingo.Utility.java
/** * Invoke the system's media scanner to add your media file to the Media Provider's database, * making it available in the Android Gallery application and to other apps. * * @param context Context to send broadcast. * @param mediaFileUri Your media file./*from w ww.j a va2s. co m*/ */ @SuppressWarnings("WeakerAccess") public static void notifyMediaScannerToAddYourFile(@NonNull Context context, @Nullable Uri mediaFileUri) { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(mediaFileUri); context.sendBroadcast(mediaScanIntent); }
From source file:ch.fixme.status.Widget.java
public static void UpdateAllWidgets(final Context ctxt) { AppWidgetManager man = AppWidgetManager.getInstance(ctxt); int[] ids = man.getAppWidgetIds(new ComponentName(ctxt, Widget.class)); Intent ui = new Intent(); ui.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); ui.putExtra(Widget.WIDGET_IDS, ids); ui.putExtra(Widget.WIDGET_FORCE, true); ctxt.sendBroadcast(ui); }
From source file:de.domjos.schooltools.helper.Helper.java
public static void sendBroadCast(Context context, Class cls) { Intent intent = new Intent(context, cls); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); int[] ids = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, cls)); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); context.sendBroadcast(intent); }
From source file:io.hypertrack.sendeta.util.images.EasyImage.java
private static void notifyGallery(Context context, URI pictureUri) throws URISyntaxException { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); File f = new File(pictureUri); Uri contentUri = Uri.fromFile(f);/*from www . j av a 2 s . c om*/ mediaScanIntent.setData(contentUri); context.sendBroadcast(mediaScanIntent); }
From source file:Main.java
public static void scanFile(String path, Context c) { System.out.println(path + " " + Build.VERSION.SDK_INT); if (Build.VERSION.SDK_INT >= 19) { MediaScannerConnection.scanFile(c, new String[] { path }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override//from w w w .j a va 2 s.com public void onScanCompleted(String path, Uri uri) { } }); } else { Uri contentUri = Uri.fromFile(new File(path)); Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, contentUri); c.sendBroadcast(mediaScanIntent); } }
From source file:Main.java
public static void addCallLog(Context context, ContentValues values, ContentValues extraValues) { ContentResolver contentResolver = context.getContentResolver(); Uri result = contentResolver.insert(CallLog.Calls.CONTENT_URI, values); if (result != null) { // Announce that to other apps final Intent broadcast = new Intent(ACTION_ANNOUNCE_SIP_CALLLOG); broadcast.putExtra(EXTRA_CALL_LOG_URI, result.toString()); String provider = extraValues.getAsString(EXTRA_SIP_PROVIDER); if (provider != null) { broadcast.putExtra(EXTRA_SIP_PROVIDER, provider); }//from ww w. ja va 2s .c o m context.sendBroadcast(broadcast); } }
From source file:de.azapps.mirakel.services.NotificationService.java
/** * Update the MirakelNotifications, Reminders and the widgets * * @param context//from ww w. j a va 2 s . co m */ public static void updateServices(final Context context) { // Widget update final Intent widgetIntent; try { widgetIntent = new Intent(context, Class.forName(DefinitionsHelper.MAINWIDGET_CLASS)); } catch (final ClassNotFoundException e) { Log.wtf(TAG, "widget not found", e); return; } widgetIntent.setAction("android.appwidget.action.APPWIDGET_UPDATE"); widgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, DefinitionsHelper.widgets); context.sendBroadcast(widgetIntent); // Dashclock update final Intent dashclockIntent = new Intent(); dashclockIntent.setAction("de.azapps.mirakel.dashclock.UPDATE"); context.sendBroadcast(dashclockIntent); if (NotificationService.notificationService == null) { final Intent intent = new Intent(context, NotificationService.class); context.startService(intent); } else { NotificationService.notificationService.notifier(); } }