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, @Nullable String receiverPermission);

Source Link

Document

Broadcast the given intent to all interested BroadcastReceivers, allowing an optional required permission to be enforced.

Usage

From source file:Main.java

public static void sendViolation(Context cxt, Intent intent, String perm) {
    cxt.sendBroadcast(intent, perm); // lint violation
}

From source file:Main.java

/**
 * Send a broadcast to external receivers.
 *//*from w w w  . j  ava  2 s .c  om*/
public static void sendToExternal(@NonNull Context cxt, @NonNull Intent intent, @NonNull String perm) {
    cxt.sendBroadcast(intent, perm);
}

From source file:Main.java

/**
 * Send a broadcast to internal receivers.
 *//*from   w  w  w. j  av  a  2s  .  co m*/
public static void sendToInternal(@NonNull Context cxt, @NonNull Intent intent) {
    String perm = cxt.getPackageName() + PERM_COMMON_BROADCAST;
    intent.setPackage(cxt.getPackageName()); // only works on Android 4.0 and higher versions
    cxt.sendBroadcast(intent, perm);
}

From source file:Main.java

/**
 * Broadcast data as a message//  ww w  .j  a va2 s  .  com
 *
 * @param context
 *     the context
 * @param data
 *     the data
 * @param action
 *     the action
 * @param custompermission
 *     the custompermission
 */
public static void broadcastData(Context context, String data, String action, String custompermission) {
    Intent i = new Intent();
    i.putExtra("data", data);
    i.setAction(action); // action ~ "com.example.android.action"
    context.sendBroadcast(i, custompermission); // custompermisson ~ "com.example.permission.MY_PERMISSION"
}

From source file:net.tawacentral.roger.secrets.OnlineAgentManager.java

/**
 * Sends out the rollcall broadcast and will keep track of all OSAs that
 * respond.//from  w ww. j  a  v  a 2  s .  co  m
 * 
 * Forget previous agents - only ones that respond are considered available.
 * 
 * @param context
 */
public static void sendRollCallBroadcast(Context context) {
    AVAILABLE_AGENTS.clear();
    Intent broadcastIntent = new Intent(ROLLCALL);
    context.sendBroadcast(broadcastIntent, SECRETS_PERMISSION);
    Log.d(LOG_TAG, "sent broadcast");
}

From source file:com.arellomobile.android.push.PushGCMIntentService.java

private static void generateBroadcast(Context context, Bundle extras) {
    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction(context.getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");
    broadcastIntent.putExtras(extras);//  w  w w . j a  v a2s  . c o  m

    JSONObject dataObject = new JSONObject();
    try {
        if (extras.containsKey("title")) {
            dataObject.put("title", extras.get("title"));
        }
        if (extras.containsKey("u")) {
            dataObject.put("userdata", new JSONObject(extras.getString("u")));
        }
    } catch (JSONException e) {
        // pass
    }

    broadcastIntent.putExtra(BasePushMessageReceiver.DATA_KEY, dataObject.toString());

    context.sendBroadcast(broadcastIntent, context.getPackageName() + ".permission.C2D_MESSAGE");
}

From source file:cm.aptoide.ptdev.preferences.ManagerPreferences.java

private void removeLauncherShortcut(Context context) {
    final Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setComponent(new ComponentName(context.getPackageName(), "cm.aptoide.ptdev.Start"));

    final Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, Aptoide.getConfiguration().getMarketName());
    shortcutIntent.setComponent(new ComponentName(context.getPackageName(), "cm.aptoide.ptdev.Start"));
    intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");

    context.sendBroadcast(intent, null);
}