Example usage for android.content Context sendBroadcast

List of usage examples for android.content Context sendBroadcast

Introduction

In this page you can find the example usage for android.content Context sendBroadcast.

Prototype

public abstract void sendBroadcast(@RequiresPermission Intent intent);

Source Link

Document

Broadcast the given intent to all interested BroadcastReceivers.

Usage

From source file:com.frostwire.android.gui.util.UIUtils.java

public static void broadcastAction(Context ctx, String actionCode, IntentByteExtra... extras) {
    if (ctx == null || actionCode == null) {
        return;/*w  ww. j  a  v a  2 s  .  co m*/
    }
    final Intent intent = new Intent(actionCode);
    if (extras != null && extras.length > 0) {
        for (IntentByteExtra extra : extras) {
            intent.putExtra(extra.name, extra.value);
        }
    }
    ctx.sendBroadcast(intent);
}

From source file:sg.macbuntu.android.pushcontacts.DeviceRegistrar.java

public static void unregisterWithServer(final Context context, final String deviceRegistrationID) {
    try {/*from   w w w.j a v  a2s .com*/
        HttpResponse res = makeRequest(context, deviceRegistrationID, UNREGISTER_URL);
        if (res.getStatusLine().getStatusCode() == 200) {
            SharedPreferences settings = Prefs.get(context);
            SharedPreferences.Editor editor = settings.edit();
            editor.remove("deviceRegistrationID");
            editor.commit();
        } else {
            Log.w(TAG, "Unregistration error " + String.valueOf(res.getStatusLine().getStatusCode()));
        }
    } catch (Exception e) {
        Log.w(TAG, "Unegistration error " + e.getMessage());
    }

    // Update dialog activity
    context.sendBroadcast(new Intent("sg.macbuntu.android.pushcontacts.UPDATE_UI"));
}

From source file:sg.macbuntu.android.pushcontacts.DeviceRegistrar.java

private static String getAuthToken(Context context, Account account) {
    String authToken = null;//from  www .ja va2 s . com
    AccountManager accountManager = AccountManager.get(context);
    try {
        AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null,
                null);
        Bundle bundle = future.getResult();
        authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
        // User will be asked for "App Engine" permission.
        if (authToken == null) {
            // No auth token - will need to ask permission from user.
            Intent intent = new Intent(ActivityUI.AUTH_PERMISSION_ACTION);
            intent.putExtra("AccountManagerBundle", bundle);
            context.sendBroadcast(intent);
        }
    } catch (OperationCanceledException e) {
        Log.w(TAG, e.getMessage());
    } catch (AuthenticatorException e) {
        Log.w(TAG, e.getMessage());
    } catch (IOException e) {
        Log.w(TAG, e.getMessage());
    }
    return authToken;
}

From source file:com.mods.grx.settings.utils.Utils.java

public static void send_bc2(final Context context) {
    Runnable BC = new Runnable() {
        @Override//from   w ww  . j av a  2  s  .  c  o m
        public void run() {
            Intent intent = new Intent();
            try {
                intent.setAction(context.getResources().getString(R.string.gs_grxBc2));
                context.sendBroadcast(intent);
            } catch (Exception e) {
                e.printStackTrace();
                Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    };

    Handler handler = new Handler();
    handler.removeCallbacks(BC);
    handler.postDelayed(BC, Long.valueOf(400));
}

From source file:Main.java

@SuppressLint("InlinedApi")
private static boolean updateGallery(Context context, Bitmap bmp, String fileNm) {
    // Insert into MediaStore.
    ContentValues values = new ContentValues();
    values.put(ImageColumns.TITLE, fileNm);
    values.put(ImageColumns.DISPLAY_NAME, fileNm);
    values.put(ImageColumns.DATE_TAKEN, System.currentTimeMillis());
    values.put(ImageColumns.MIME_TYPE, "image/jpeg");
    values.put(ImageColumns.ORIENTATION, 0);
    values.put(ImageColumns.DATA, PIC_ROOT_PATH + fileNm);
    values.put(ImageColumns.WIDTH, bmp.getWidth());
    values.put(ImageColumns.HEIGHT, bmp.getHeight());

    try {/* w  ww.  j a  v a2s .co m*/
        Uri uri = context.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
        if (uri == null) {
            Log.e("storeImage", "Failed to insert MediaStore");
            return false;
        } else {
            context.sendBroadcast(new Intent("com.android.camera.NEW_PICTURE", uri));
        }
    } catch (Exception e) {
        Log.e("storeImage", "Failed to write MediaStore", e);
        return false;
    }

    return true;
}

From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java

public static void addImageToGallery(Context c, Uri contentUri) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(contentUri);
    c.sendBroadcast(mediaScanIntent);
}

From source file:com.brewcrewfoo.performance.util.Helpers.java

public static void updateAppWidget(Context context) {
    AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
    ComponentName widgetComponent = new ComponentName(context, PCWidget.class);
    int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
    Intent update = new Intent();
    update.setAction("com.brewcrewfoo.performance.ACTION_FREQS_CHANGED");
    update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
    context.sendBroadcast(update);
}

From source file:info.papdt.blacklight.support.Utility.java

public static void notifyScanPhotos(Context context, String path) {
    Intent i = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    Uri uri = Uri.fromFile(new File(path));
    i.setData(uri);//from w w w .  j  av a 2s  . c  o m
    context.sendBroadcast(i);
}

From source file:library.artaris.cn.library.utils.SystemUtils.java

/**
 * ??/*from   w ww  . j  a va  2  s  .  c o  m*/
 * @param context
 * @param shortCutName
 * @param iconId
 * @param presentIntent
 */
public static void createShortcut(Context context, 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(context, iconId));
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, presentIntent);
    context.sendBroadcast(shortcutIntent);
}

From source file:com.wbtech.ums.UmsAgent.java

private static void postClientDatas(Context context) {
    if (isFirst) {
        Intent intent = new Intent();
        intent.setAction("cobub.razor.message");
        intent.putExtra("deviceid", CommonUtil.getDeviceID(context));
        context.sendBroadcast(intent);
        JSONObject clientData = getClientDataJSONObject(context);

        if (1 == CommonUtil.getReportPolicyMode(context) & CommonUtil.isNetworkAvailable(context)) {
            MyMessage message = NetworkUitlity.post(UmsConstants.preUrl + UmsConstants.clientDataUrl,
                    clientData.toString());
            if (!message.isFlag()) {
                saveInfoToFile("clientData", clientData, context);
                CommonUtil.printLog("Errorinfo", message.getMsg());
            }/* w w w  .  j ava 2s .c om*/
        } else {
            saveInfoToFile("clientData", clientData, context);
        }
        isFirst = false;

    }
}