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

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static void toggleAirplane(Context context) {

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
        return;//w  w  w.j  a v  a  2 s .c om

    int state = 0;
    try {
        if (isJBean())
            state = Settings.System.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON);
        else
            state = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON);
    } catch (SettingNotFoundException e) {
        e.printStackTrace();
    }

    if (state == 0) {
        if (isJBean())
            Settings.System.putInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
        else
            Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 1);
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", true);
        context.sendBroadcast(intent);
    } else {
        if (isJBean())
            Settings.System.putInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0);
        else
            Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", false);
        context.sendBroadcast(intent);
    }
}

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

public static void registerWithServer(final Context context, final String deviceRegistrationID) {
    try {/*from  w ww.j a v  a 2  s  . co m*/
        HttpResponse res = makeRequest(context, deviceRegistrationID, REGISTER_URL);
        if (res.getStatusLine().getStatusCode() == 200) {
            SharedPreferences settings = Prefs.get(context);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString("deviceRegistrationID", deviceRegistrationID);
            editor.commit();
        } else {
            Log.w(TAG, "Registration error " + String.valueOf(res.getStatusLine().getStatusCode()));
        }
    } catch (PendingAuthException e) {
        // Ignore - we'll reregister later
    } catch (Exception e) {
        Log.w(TAG, "Registration error " + e.getMessage());
    }

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

From source file:mx.klozz.xperience.tweaker.helpers.Helpers.java

public static void updateAppWidget(Context context) {
    AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
    ComponentName widgetComponent = new ComponentName(context, Widget.class);
    int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
    Intent update = new Intent();
    update.setAction("mx.klozz.xperience.tweaker.ACTION_FREQS_CHANGED");
    update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
    context.sendBroadcast(update);
}

From source file:Main.java

public static void delShortcutFromDesktop(Context paramContext, String packageName, String cls,
        String appName) {/*from  ww w  . j  a v  a  2 s. c o m*/
    Intent localIntent1 = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
    String str = appName;
    PackageManager localPackageManager = paramContext.getPackageManager();
    int i = 8320;
    try {
        ApplicationInfo localApplicationInfo = localPackageManager.getApplicationInfo(packageName, i);
        if (str == null)
            str = localPackageManager.getApplicationLabel(localApplicationInfo).toString();
        localIntent1.putExtra("android.intent.extra.shortcut.NAME", str);
        ComponentName localComponentName = new ComponentName(packageName, cls);
        Intent localIntent2 = new Intent(Intent.ACTION_MAIN).setComponent(localComponentName);
        localIntent2.addCategory(Intent.CATEGORY_LAUNCHER);
        localIntent1.putExtra("android.intent.extra.shortcut.INTENT", localIntent2);
        paramContext.sendBroadcast(localIntent1);
        return;
    } catch (PackageManager.NameNotFoundException localNameNotFoundException) {
        while (true)
            localNameNotFoundException.printStackTrace();
    }
}

From source file:io.rapidpro.androidchannel.RapidPro.java

/**
 * Releases our relayer, resetting all messages and data.
 *
 * @param context//from   w w w.j  a v a 2s.c o  m
 */
public static void release(Context context) {
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
    editor.remove(SettingsActivity.RELAYER_SECRET);
    editor.remove(SettingsActivity.RELAYER_ID);
    editor.remove(SettingsActivity.RELAYER_ORG);
    editor.commit();

    // remove all commands
    DBCommandHelper.clearCommands(context);

    // notify everybody that our state has changed
    Intent intent = new Intent(Intents.UPDATE_RELAYER_STATE);
    context.sendBroadcast(intent);
}

From source file:de.ub0r.android.websms.WebSMSReceiver.java

@SuppressLint("InlinedApi")
private static void sendMessageToCallMeter(final Context context, final ConnectorSpec specs, final Uri u) {
    Log.d(TAG, "send broadcast to CallMeter3G");
    Intent intent = new Intent(ACTION_CM_WEBSMS);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    intent.putExtra(EXTRA_WEBSMS_URI, u.toString());
    intent.putExtra(EXTRA_WEBSMS_CONNECTOR, specs.getName().toLowerCase());
    context.sendBroadcast(intent);
}

From source file:de.ub0r.android.websms.WebSMSReceiver.java

private static void sendMessageToSMSdroid(final Context context, final ConnectorSpec specs,
        final ConnectorCommand command) {
    Log.d(TAG, "send broadcast to SMSdroid");
    Intent intent = new Intent(ACTION_SMSDROID_WEBSMS);
    intent.putExtra("address", command.getRecipients());
    intent.putExtra("body", command.getText());
    intent.putExtra("connector_name", specs.getName());
    context.sendBroadcast(intent);
}

From source file:com.fvd.nimbus.MainActivity.java

public static void deleteShortcut(Context context) {
    Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Nimbus Clipper");
    ComponentName comp = new ComponentName("com.fvd.nimbus", "com.fvd.nimbus.MainActivity");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
    context.sendBroadcast(shortcut);
}

From source file:com.farmerbb.secondscreen.util.U.java

public static void listProfilesBroadcast(Context context) {
    Intent listProfilesIntent = new Intent();
    listProfilesIntent.setAction(U.LIST_PROFILES);
    context.sendBroadcast(listProfilesIntent);
}

From source file:net.ustyugov.jtalk.Notify.java

public static void offlineNotify(Context context, String state) {
    if (state == null)
        state = "";
    Intent i = new Intent(context, RosterActivity.class);
    i.setAction(Intent.ACTION_MAIN);/*from  w  w w .  j ava2s .co  m*/
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i, 0);

    JTalkService service = JTalkService.getInstance();
    service.setGlobalState(state);
    context.sendBroadcast(new Intent(Constants.UPDATE));

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher));
    mBuilder.setSmallIcon(R.drawable.stat_offline);
    mBuilder.setContentTitle(context.getString(R.string.app_name));
    mBuilder.setContentText(state);
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);

    NotificationManager mng = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mng.notify(NOTIFICATION, mBuilder.build());
}