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:org.mozilla.mozstumbler.client.TurnOffReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (intent != null && intent.getAction() != null && intent.getAction().contains("BATTERY_LOW")) {
        Log.d(LOG_TAG, "Battery Low Received");
        context.sendBroadcast(new Intent(MainApp.INTENT_TURN_OFF));
    } else {// w  ww  .j  a  va2s  .  c  om
        LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(MainApp.ACTION_UI_PAUSE_SCANNING));
    }
}

From source file:com.google.android.apps.chrometophone.C2DMReceiver.java

@Override
public void onError(Context context, String errorId) {
    context.sendBroadcast(new Intent("com.google.ctp.UPDATE_UI"));
}

From source file:ro.corneliudascalu.gcm.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from  w  w  w  .jav  a  2  s  .co  m*/
private static void generateNotification(Context context, String message) {
    // long when = System.currentTimeMillis();
    // NotificationManager notificationManager = (NotificationManager)
    // context.getSystemService(Context.NOTIFICATION_SERVICE);
    // Notification notification = new Notification(R.drawable.ic_launcher,
    // message, when);
    // String title = context.getString(R.string.app_name);
    // Intent notificationIntent = new Intent(context,
    // SamplePushActivity.class);
    // // set intent so it does not start a new activity
    // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
    // Intent.FLAG_ACTIVITY_SINGLE_TOP);
    // PendingIntent intent = PendingIntent.getActivity(context, 0,
    // notificationIntent, 0);
    // notification.setLatestEventInfo(context, title, message, intent);
    // notification.flags |= Notification.FLAG_AUTO_CANCEL;
    // notificationManager.notify(0, notification);

    Log.d(TAG, "Received: " + message);

    Intent intent2 = new Intent(MESSAGE_RECEIVED_ACTION);
    intent2.putExtra(GCM_DATA, message);

    context.sendBroadcast(intent2);
}

From source file:com.bandbaaja.c2dm.DeviceRegistrar.java

public static void unregisterWithServer(final Context context, final String deviceRegistrationID) {
    new Thread(new Runnable() {
        public void run() {
            Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI");
            try {
                HttpResponse res = makeRequest(context, deviceRegistrationID, UNREGISTER_PATH);
                if (res.getStatusLine().getStatusCode() != 200) {
                    Log.w(TAG, "Unregistration error " + String.valueOf(res.getStatusLine().getStatusCode()));
                }//from  w w  w.j a  v  a2s  .  c o m
            } catch (Exception e) {
                Log.w(TAG, "Unregistration error " + e.getMessage());
            } finally {
                SharedPreferences settings = Prefs.get(context);
                SharedPreferences.Editor editor = settings.edit();
                editor.remove("deviceRegistrationID");
                editor.remove("accountName");
                editor.commit();
                updateUIIntent.putExtra(STATUS_EXTRA, UNREGISTERED_STATUS);
            }

            // Update dialog activity
            context.sendBroadcast(updateUIIntent);
        }
    }).start();
}

From source file:com.drextended.actionhandler.action.IntentAction.java

/**
 * Broadcast the given intent to all interested BroadcastReceivers.
 * Override this method if you need specific behaviour.
 *
 * @param context The Context, which generally get from view by {@link View#getContext()}
 * @param intent  The Intent to broadcast, provided by {@link #getIntent(View, Context, String, Object)}
 *///w w  w .java  2 s  .c o  m
protected void sendBroadcast(Context context, Intent intent) {
    context.sendBroadcast(intent);
}

From source file:com.parse.PushRouter.java

public synchronized boolean handlePush(String pushId, String timestamp, String channel, JSONObject data) {
    if (ParseTextUtils.isEmpty(pushId) || ParseTextUtils.isEmpty(timestamp)) {
        return false;
    }//w w  w. j av a 2s. c o m

    if (!history.tryInsertPush(pushId, timestamp)) {
        return false;
    }

    // Persist the fact that we've seen this push.
    saveStateToDisk();

    Bundle extras = new Bundle();
    extras.putString(ParsePushBroadcastReceiver.KEY_PUSH_CHANNEL, channel);
    if (data == null) {
        extras.putString(ParsePushBroadcastReceiver.KEY_PUSH_DATA, "{}");
    } else {
        extras.putString(ParsePushBroadcastReceiver.KEY_PUSH_DATA, data.toString());
    }

    Intent intent = new Intent(ParsePushBroadcastReceiver.ACTION_PUSH_RECEIVE);
    intent.putExtras(extras);

    // Set the package name to keep this intent within the given package.
    Context context = Parse.getApplicationContext();
    intent.setPackage(context.getPackageName());
    context.sendBroadcast(intent);

    return true;
}

From source file:com.lvlstudios.android.gtmessage.DeviceRegistrar.java

public static void unregisterWithServer(final Context context, final String deviceRegistrationID) {
    new Thread(new Runnable() {
        @Override//from w ww. j a  v  a  2s.com
        public void run() {
            Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI");
            try {
                HttpResponse res = makeRequest(context, deviceRegistrationID, UNREGISTER_PATH);
                if (res.getStatusLine().getStatusCode() != 200) {
                    Log.w(TAG, "Unregistration error " + String.valueOf(res.getStatusLine().getStatusCode()));
                }
            } catch (Exception e) {
                Log.w(TAG, "Unregistration error " + e.getMessage());
            } finally {
                SharedPreferences settings = Prefs.get(context);
                SharedPreferences.Editor editor = settings.edit();
                editor.remove("deviceRegistrationID");
                editor.remove("accountName");
                editor.commit();
                updateUIIntent.putExtra(STATUS_EXTRA, UNREGISTERED_STATUS);
            }

            // Update dialog activity
            context.sendBroadcast(updateUIIntent);
        }
    }).start();
}

From source file:com.dmbstream.android.util.Util.java

/**
 * <p>Broadcasts the given song info as the new song being played.</p>
 *//*from  w  w  w  .j a v  a2  s .com*/
public static void broadcastNewTrackInfo(Context context, Track song) {
    Intent intent = new Intent(EVENT_META_CHANGED);

    if (song != null) {
        intent.putExtra("title", song.title);
        intent.putExtra("artist", song.artist);
        intent.putExtra("album", song.concert);
    } else {
        intent.putExtra("title", "");
        intent.putExtra("artist", "");
        intent.putExtra("album", "");
        intent.putExtra("coverart", "");
    }

    context.sendBroadcast(intent);
}

From source file:com.bandbaaja.c2dm.DeviceRegistrar.java

public static void registerWithServer(final Context context, final String deviceRegistrationID) {
    new Thread(new Runnable() {
        public void run() {
            Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI");
            try {
                HttpResponse res = makeRequest(context, deviceRegistrationID, REGISTER_PATH);
                if (res.getStatusLine().getStatusCode() == 200) {
                    SharedPreferences settings = Prefs.get(context);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString("deviceRegistrationID", deviceRegistrationID);
                    editor.commit();//  ww  w .  j  a  v a 2s  . c  om
                    updateUIIntent.putExtra(STATUS_EXTRA, REGISTERED_STATUS);
                } else if (res.getStatusLine().getStatusCode() == 400) {
                    updateUIIntent.putExtra(STATUS_EXTRA, AUTH_ERROR_STATUS);
                } else {
                    Log.w(TAG, "Registration error " + String.valueOf(res.getStatusLine().getStatusCode()));
                    updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
                }
                context.sendBroadcast(updateUIIntent);
            } catch (Exception e) {
                Log.w(TAG, "Registration error " + e.getMessage());
                updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
                context.sendBroadcast(updateUIIntent);
            }
        }
    }).start();
}

From source file:com.browsertophone.DeviceRegistrar.java

public static void registerWithServer(final Context context, final String deviceRegistrationID) {
    new Thread(new Runnable() {
        public void run() {
            Intent updateUIIntent = new Intent("com.browsertophone.btp.UPDATE_UI");
            try {
                HttpResponse res = makeRequest(context, deviceRegistrationID, REGISTER_PATH);
                if (res.getStatusLine().getStatusCode() == 200) {
                    SharedPreferences settings = Prefs.get(context);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString("deviceRegistrationID", deviceRegistrationID);
                    editor.commit();//www . j a  v  a2  s. c o m
                    updateUIIntent.putExtra(STATUS_EXTRA, REGISTERED_STATUS);
                } else if (res.getStatusLine().getStatusCode() == 400) {
                    updateUIIntent.putExtra(STATUS_EXTRA, AUTH_ERROR_STATUS);
                } else {
                    Log.w(TAG, "Registration error " + String.valueOf(res.getStatusLine().getStatusCode()));
                    updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
                }
                context.sendBroadcast(updateUIIntent);
            } catch (AppEngineClient.PendingAuthException pae) {
                // Ignore - we'll reregister later
            } catch (Exception e) {
                Log.w(TAG, "Registration error " + e.getMessage());
                updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
                context.sendBroadcast(updateUIIntent);
            }
        }
    }).start();
}