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:Main.java

public static void setAppState(int i, Context context) {
    Intent stateUpdate = new Intent("com.quicinc.Trepn.UpdateAppState");
    stateUpdate.putExtra("com.quicinc.Trepn.UpdateAppState.Value", i);
    context.sendBroadcast(stateUpdate);
}

From source file:Main.java

static void displayMessage(Context context, Intent in) {

    Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
    intent.replaceExtras(in);/*from w  w  w.j av a  2  s . co  m*/

    context.sendBroadcast(intent);
}

From source file:Main.java

public static void setApiKeyAndSecret(String apiKey, String apiSecret, Context context) {
    Intent intent = new Intent(ACTION_SET_API_CREDENTIAL).putExtra(EXTRA_API_KEY, apiKey)
            .putExtra(EXTRA_API_SECRET, apiSecret);
    context.sendBroadcast(intent);
}

From source file:Main.java

public static final void openGPS(Context context) {
    Intent intent = new Intent("com.nd.android.starapp.ui.jay.weibo.activity.GPS");
    intent.putExtra("enabled", true);
    context.sendBroadcast(intent);

    String provider = Settings.Secure.getString(context.getContentResolver(),
            Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    if (!provider.contains("gps")) { //if gps is disabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3"));
        context.sendBroadcast(poke);//from w  ww.j a v  a 2  s .c om
    }
}

From source file:Main.java

/**
 * Notifies UI to display a message./*  w  w  w  . j a v  a 2 s. co  m*/
 * <p>
 * This method is defined in the common helper because it's used both by the
 * UI and the background service.
 * 
 * @param context
 *            application's context.
 * @param message
 *            message to be displayed.
 */
static void displayMessage(Context context, String message) {
    Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
    intent.putExtra("message", message);

    context.sendBroadcast(intent);
}

From source file:Main.java

/**
 * Notifies UI to display a message.// w w w  .jav a2 s.c  om
 * <p>
 * This method is defined in the common helper because it's used both by
 * the UI and the background service.
 *
 * @param context application's context.
 * @param message message to be displayed.
 */

static void displaySystemMessage(Context context, String message) {
    Intent intent = new Intent(SYSTEM_MESSAGE_ACTION);
    intent.putExtra(EXTRA_MESSAGE, message);
    context.sendBroadcast(intent);
}

From source file:Main.java

public static void scanDirAsync(Context ctx, String dir) {
    Intent scanIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_DIR");
    scanIntent.setData(Uri.fromFile(new File(dir)));
    ctx.sendBroadcast(scanIntent);
}

From source file:Main.java

public static void sendBroadcast(Context context, String action, Bundle bundle) {
    Intent intent = new Intent(action);
    if (bundle != null) {
        intent.putExtras(bundle);//from w  ww  .ja  v a  2 s  . c om
    }
    context.sendBroadcast(intent);
}

From source file:Main.java

/**
 * Notifies UI to display a message./* w ww  . jav  a  2s  .c  om*/
 * <p>
 * This method is defined in the common helper because it's used both by
 * the UI and the background service.
 *
 * @param context application's context.
 * @param message message to be displayed.
 */
static void displayMessage(Context context, String message) {
    Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
    intent.putExtra(EXTRA_MESSAGE, message);
    context.sendBroadcast(intent);
}

From source file:Main.java

/**
 * Notifies UI to display a message./*  w w w  . j  ava  2s  .c o m*/
 * <p>
 * This method is defined in the common helper because it's used both by
 * the UI and the background service.
 *
 * @param context application's context.
 * @param message message to be displayed.
 */
public static void displayMessage(Context context, String message) {
    Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
    intent.putExtra(EXTRA_MESSAGE, message);
    context.sendBroadcast(intent);
}