List of usage examples for android.content Context sendOrderedBroadcast
public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent, @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
From source file:com.tenforwardconsulting.cordova.bgloc.AbstractLocationProvider.java
public void broadcastLocation(Location location) { final LocationProxy bgLocation = LocationProxy.fromAndroidLocation(location); bgLocation.setServiceProvider(config.getServiceProvider()); if (config.isDebugging()) { bgLocation.setDebug(true);// ww w .j av a 2s . c o m persistLocation(bgLocation); } Log.d(TAG, "Broadcasting update message: " + bgLocation.toString()); try { String locStr = bgLocation.toJSONObject().toString(); Intent intent = new Intent(Constant.ACTION_FILTER); intent.putExtra(Constant.ACTION, Constant.ACTION_LOCATION_UPDATE); intent.putExtra(Constant.DATA, locStr); if (config.getUrl() != null) { Log.i(TAG, "Sending URL detail"); intent.putExtra("url", config.getUrl()); intent.putExtra("method", config.getMethod()); intent.putExtra("headers", config.getHeaders()); intent.putExtra("params", config.getParams()); } else { Log.i(TAG, "No URL defined"); } context.sendOrderedBroadcast(intent, null, new BroadcastReceiver() { // @SuppressLint("NewApi") @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "Final Result Receiver"); Bundle results = getResultExtras(true); if (results.getString(Constant.LOCATION_SENT_INDICATOR) == null) { Log.w(TAG, "Main activity seems to be killed"); if (config.getStopOnTerminate() == false) { bgLocation.setDebug(false); persistLocation(bgLocation); Log.d(TAG, "Persisting location. Reason: Main activity was killed."); } } } }, null, Activity.RESULT_OK, null, null); } catch (JSONException e) { Log.w(TAG, "Failed to broadcast location"); } }
From source file:com.neusou.bioroid.restful.RestfulClient.java
/** * Sends an Intent callback to the original caller * @param ctx//from w w w.j av a 2 s. c o m * @param data */ public void broadcastCallback(Context ctx, Bundle data, String action) { if (ctx != null) { //Log.d(LOG_TAG,"broadcastCallback action:"+action); Intent i = new Intent(action); //i.putExtra(, value); i.putExtras(data); //runs on the context main thread ctx.sendOrderedBroadcast(i, null, mLastCallbackReceiver, null, Activity.RESULT_OK, null, null); //ctx.sendBroadcast(i); } }
From source file:de.ub0r.android.websms.WebSMS.java
/** * Send a command as broadcast.//from w ww . j a v a 2s.co m * * @param context Current context * @param connector {@link ConnectorSpec} * @param command {@link ConnectorCommand} */ static void runCommand(final Context context, final ConnectorSpec connector, final ConnectorCommand command) { connector.setErrorMessage((String) null); final Intent intent = command.setToIntent(null); short t = command.getType(); boolean sendOrdered = false; switch (t) { case ConnectorCommand.TYPE_BOOTSTRAP: sendOrdered = true; intent.setAction(connector.getPackage() + Connector.ACTION_RUN_BOOTSTRAP); connector.addStatus(ConnectorSpec.STATUS_BOOTSTRAPPING); break; case ConnectorCommand.TYPE_SEND: sendOrdered = true; intent.setAction(connector.getPackage() + Connector.ACTION_RUN_SEND); connector.setToIntent(intent); connector.addStatus(ConnectorSpec.STATUS_SENDING); if (command.getResendCount() == 0) { WebSMSReceiver.saveMessage(me, connector, command, WebSMSReceiver.MESSAGE_TYPE_DRAFT); } break; case ConnectorCommand.TYPE_UPDATE: intent.setAction(connector.getPackage() + Connector.ACTION_RUN_UPDATE); connector.addStatus(ConnectorSpec.STATUS_UPDATING); break; default: break; } updateProgressBar(); intent.setFlags(intent.getFlags() | Intent.FLAG_INCLUDE_STOPPED_PACKAGES); Log.d(TAG, "send broadcast: " + intent.getAction()); if (sendOrdered) { context.sendOrderedBroadcast(intent, null, new BroadcastReceiver() { @Override public void onReceive(final Context context, final Intent intent) { if (this.getResultCode() != Activity.RESULT_OK) { ConnectorCommand command = new ConnectorCommand(intent); ConnectorSpec specs = new ConnectorSpec(intent); specs.setErrorMessage(// TODO: localize "Connector did not react on message"); WebSMSReceiver.handleSendCommand(context, specs, command); } } }, null, Activity.RESULT_CANCELED, null, null); } else { context.sendBroadcast(intent); } }