List of usage examples for android.content Context sendBroadcast
public abstract void sendBroadcast(@RequiresPermission Intent intent);
From source file:com.agiro.scanner.android.AppEngineClient.java
private String getAuthToken(Context context, Account account) { String authToken = null;/*from www . ja v a2 s. c om*/ AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); Account[] accs = accountManager.getAccounts(); Log.v(TAG, "Account size = " + accs.length); Log.v(TAG, "Listing accounts"); for (Account acc : accs) { Log.v(TAG, "Account: " + acc); } authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); // User will be asked for "App Engine" permission. if (authToken == null) { Log.e(TAG, "No authToken"); // No auth token - will need to ask permission from user. Intent intent = new Intent("com.google.ctp.AUTH_PERMISSION"); intent.putExtra("AccountManagerBundle", bundle); context.sendBroadcast(intent); } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:io.rapidpro.androidchannel.RapidPro.java
public static void broadcastUpdatedCounts(Context context) { Intent intent = new Intent(); intent.setAction(Intents.UPDATE_COUNTS); intent.addCategory(Intent.CATEGORY_DEFAULT); int sent = RapidPro.get().getTotalSent(); int capacity = RapidPro.get().getSendCapacity(); int outgoing = DBCommandHelper.getCommandCount(context, DBCommandHelper.IN, DBCommandHelper.BORN, MTTextMessage.CMD)/*from w ww. j a v a 2 s . c o m*/ + DBCommandHelper.getCommandCount(context, DBCommandHelper.IN, MTTextMessage.PENDING, MTTextMessage.CMD); int incoming = DBCommandHelper.getMessagesReceivedInWindow(context); int retry = DBCommandHelper.getCommandCount(context, DBCommandHelper.IN, MTTextMessage.RETRY, MTTextMessage.CMD); int sync = DBCommandHelper.getCommandCount(context, DBCommandHelper.OUT, DBCommandHelper.BORN, null); intent.putExtra(Intents.SENT_EXTRA, sent); intent.putExtra(Intents.CAPACITY_EXTRA, capacity); intent.putExtra(Intents.OUTGOING_EXTRA, outgoing); intent.putExtra(Intents.INCOMING_EXTRA, incoming); intent.putExtra(Intents.RETRY_EXTRA, retry); intent.putExtra(Intents.SYNC_EXTRA, sync); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); intent.putExtra(Intents.CONNECTION_UP_EXTRA, prefs.getBoolean(SettingsActivity.CONNECTION_UP, true)); intent.putExtra(Intents.LAST_SMS_SENT, prefs.getLong(SettingsActivity.LAST_SMS_SENT, 0)); intent.putExtra(Intents.LAST_SMS_RECEIVED, prefs.getLong(SettingsActivity.LAST_SMS_RECEIVED, 0)); intent.putExtra(Intents.IS_PAUSED, prefs.getBoolean(SettingsActivity.IS_PAUSED, false)); context.sendBroadcast(intent); }
From source file:com.ubikod.capptain.android.sdk.track.CapptainTrackReceiver.java
@Override public void onReceive(Context context, Intent intent) { /* Once the application identifier is known */ if ("com.ubikod.capptain.intent.action.APPID_GOT".equals(intent.getAction())) { /* Init the tracking agent */ String appId = intent.getStringExtra("appId"); CapptainTrackAgent.getInstance(context).onAppIdGot(appId); }/*from w ww. j a v a 2 s. c o m*/ /* During installation, an install referrer may be triggered */ else if ("com.android.vending.INSTALL_REFERRER".equals(intent.getAction())) { /* Forward this action to configured receivers */ String forwardList = CapptainUtils.getMetaData(context) .getString("capptain:track:installReferrerForwardList"); if (forwardList != null) for (String component : forwardList.split(",")) if (!component.equals(getClass().getName())) { Intent clonedIntent = new Intent(intent); clonedIntent.setComponent(new ComponentName(context, component)); context.sendBroadcast(clonedIntent); } /* Guess store from referrer */ String referrer = Uri.decode(intent.getStringExtra("referrer")); String store; /* GetJar uses an opaque string always starting with z= */ if (referrer.startsWith("z=")) store = "GetJar"; /* Assume Android Market otherwise */ else store = "Android Market"; /* Look for a source parameter */ Uri uri = Uri.parse("a://a?" + referrer); String source = uri.getQueryParameter("utm_source"); /* * Skip "androidmarket" source, this is the default one when not set or installed via web * Android Market. */ if ("androidmarket".equals(source)) source = null; /* Send app info to register store/source */ Bundle appInfo = new Bundle(); appInfo.putString("store", store); if (source != null) { /* Parse source, if coming from capptain, it may be a JSON complex object */ try { /* Convert JSON to bundle (just flat strings) */ JSONObject jsonInfo = new JSONObject(source); Iterator<?> keyIt = jsonInfo.keys(); while (keyIt.hasNext()) { String key = keyIt.next().toString(); appInfo.putString(key, jsonInfo.getString(key)); } } catch (JSONException jsone) { /* Not an object, process as a string */ appInfo.putString("source", source); } } /* Send app info */ CapptainAgent.getInstance(context).sendAppInfo(appInfo); } }
From source file:github.daneren2005.dsub.util.Util.java
/** * <p>Broadcasts the given song info as the new song being played.</p> */// ww w. ja v a2s .co m public static void broadcastNewTrackInfo(Context context, MusicDirectory.Entry song) { DownloadService downloadService = (DownloadService) context; Intent intent = new Intent(EVENT_META_CHANGED); Intent avrcpIntent = new Intent(AVRCP_METADATA_CHANGED); if (song != null) { intent.putExtra("title", song.getTitle()); intent.putExtra("artist", song.getArtist()); intent.putExtra("album", song.getAlbum()); File albumArtFile = FileUtil.getAlbumArtFile(context, song); intent.putExtra("coverart", albumArtFile.getAbsolutePath()); avrcpIntent.putExtra("playing", true); } else { intent.putExtra("title", ""); intent.putExtra("artist", ""); intent.putExtra("album", ""); intent.putExtra("coverart", ""); avrcpIntent.putExtra("playing", false); } addTrackInfo(context, song, avrcpIntent); context.sendBroadcast(intent); context.sendBroadcast(avrcpIntent); }
From source file:com.yahala.android.NotificationsController.java
private void setBadge(Context context, int count) { try {//from w w w.ja v a 2 s. c om String launcherClassName = getLauncherClassName(context); // FileLog.e("launcherClassName",launcherClassName+""); if (launcherClassName == null) { return; } Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE"); intent.putExtra("badge_count", count); intent.putExtra("badge_count_package_name", context.getPackageName()); intent.putExtra("badge_count_class_name", launcherClassName); context.sendBroadcast(intent); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:de.ub0r.android.websms.connector.o2.ConnectorO2.java
/** * Load captcha and wait for user input to solve it. * /*from www . j a va2 s .c o m*/ * @param context * {@link Context} * @param flow * _flowExecutionKey * @return true if captcha was solved * @throws IOException * IOException */ private boolean solveCaptcha(final Context context, final String flow) throws IOException { HttpResponse response = Utils.getHttpClient(URL_CAPTCHA, null, null, TARGET_AGENT, URL_LOGIN, ENCODING, O2_SSL_FINGERPRINTS); int resp = response.getStatusLine().getStatusCode(); if (resp != HttpURLConnection.HTTP_OK) { throw new WebSMSException(context, R.string.error_http, "" + resp); } BitmapDrawable captcha = new BitmapDrawable(response.getEntity().getContent()); final Intent intent = new Intent(Connector.ACTION_CAPTCHA_REQUEST); intent.putExtra(Connector.EXTRA_CAPTCHA_DRAWABLE, captcha.getBitmap()); captcha = null; this.getSpec(context).setToIntent(intent); context.sendBroadcast(intent); try { synchronized (CAPTCHA_SYNC) { CAPTCHA_SYNC.wait(CAPTCHA_TIMEOUT); } } catch (InterruptedException e) { Log.e(TAG, null, e); return false; } if (captchaSolve == null) { return false; } // got user response, try to solve captcha Log.d(TAG, "got solved captcha: " + captchaSolve); final ArrayList<BasicNameValuePair> postData = // . new ArrayList<BasicNameValuePair>(3); postData.add(new BasicNameValuePair("_flowExecutionKey", flow)); postData.add(new BasicNameValuePair("_eventId", "submit")); postData.add(new BasicNameValuePair("riddleValue", captchaSolve)); response = Utils.getHttpClient(URL_SOLVECAPTCHA, null, postData, TARGET_AGENT, URL_LOGIN, ENCODING, O2_SSL_FINGERPRINTS); Log.d(TAG, postData.toString()); resp = response.getStatusLine().getStatusCode(); if (resp != HttpURLConnection.HTTP_OK) { throw new WebSMSException(context, R.string.error_http, "" + resp); } final String mHtmlText = Utils.stream2str(response.getEntity().getContent()); if (mHtmlText.indexOf(CHECK_WRONGCAPTCHA) > 0) { throw new WebSMSException(context, R.string.error_wrongcaptcha); } return true; }
From source file:org.restcomm.app.qoslib.Utils.QosAPI.java
/** * Trigger an Active Event manually from the application, generally this is a type of active test or coverage gathering * Allowable events are from {@link ActiveEvent} * * @param context pass your context//from w w w . j a va2s .com * @param {@link ActiveEvent} type of event to start * @return 0 if successful, 1 if event type can't be triggered, 2 if event is not enabled for your user, 3 if app doesnt have necessary permissions */ public static int startEvent(Context context, ActiveEvent event) { if (!isEventEnabled(context, event.eventType)) return 2; // Event has not been enabled by server if (!isEventPermitted(context, event.eventType, 1)) return 3; // Event doesnt have enough manifest permissions to run JSONObject jobj = new JSONObject(); try { // Trigger certain events using the Library if (event == ActiveEvent.SPEED_TEST) jobj.put("mmctype", "speed"); else if (event == ActiveEvent.UPDATE_EVENT) jobj.put("mmctype", "ue"); else if (event == ActiveEvent.AUDIO_TEST) jobj.put("mmctype", "audio"); else if (event == ActiveEvent.CONNECT_TEST) jobj.put("mmctype", "latency"); else if (event == ActiveEvent.SMS_TEST) jobj.put("mmctype", "sms"); else if (event == ActiveEvent.VIDEO_TEST) jobj.put("mmctype", "video"); else if (event == ActiveEvent.YOUTUBE_TEST) jobj.put("mmctype", "youtube"); else if (event == ActiveEvent.WEB_TEST) jobj.put("mmctype", "web"); else if (event == ActiveEvent.VOICE_QUALITY_TEST) jobj.put("mmctype", "vq"); else if (event == ActiveEvent.COVERAGE_EVENT) jobj.put("mmctype", "fill"); else return 1; // Event can't be triggered manually } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "Library startEvent", "exception", e); } String command = "[" + jobj.toString() + "]"; Intent mmcintent = new Intent(IntentHandler.COMMAND); mmcintent.putExtra(IntentHandler.COMMAND_EXTRA, command); context.sendBroadcast(mmcintent); return 0; }
From source file:org.runnerup.tracker.component.TrackerPebble.java
@Override public TrackerComponent.ResultCode onInit(final Callback callback, final Context context) { this.context = context; if (!isConnected() || !PebbleKit.areAppMessagesSupported(context)) { return ResultCode.RESULT_NOT_SUPPORTED; }/*w ww .jav a 2s . c om*/ customizeWatchApp(); PebbleKit.startAppOnPebble(context, Constants.SPORTS_UUID); sportsDataHandler = new PebbleKit.PebbleDataReceiver(Constants.SPORTS_UUID) { @Override public void receiveData(final Context pebbleContext, final int transactionId, final PebbleDictionary data) { try { int newState = data.getUnsignedIntegerAsLong(Constants.SPORTS_STATE_KEY).intValue(); PebbleKit.sendAckToPebble(context, transactionId); if (newState == Constants.SPORTS_STATE_PAUSED || newState == Constants.SPORTS_STATE_RUNNING) { if (tracker.getWorkout() == null) { Intent startBroadcastIntent = new Intent(); startBroadcastIntent .setAction(org.runnerup.common.util.Constants.Intents.START_WORKOUT); context.sendBroadcast(startBroadcastIntent); } else if (tracker.getWorkout().isPaused()) { sendLocalBroadcast(org.runnerup.common.util.Constants.Intents.RESUME_WORKOUT); } else { sendLocalBroadcast(org.runnerup.common.util.Constants.Intents.PAUSE_WORKOUT); } } } catch (Exception ex) { Toast.makeText(context, ex.toString(), Toast.LENGTH_LONG).show(); } } }; PebbleKit.registerReceivedDataHandler(context, sportsDataHandler); return ResultCode.RESULT_OK; }
From source file:com.p2p.misc.DeviceUtility.java
public void toggleGPSOFF(boolean enable, Context mContext) { try {//from w w w .j a va2 s . co m String provider = Settings.Secure.getString(mContext.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")); mContext.sendBroadcast(poke); System.out.println("GPS is turn OFF"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private void notifyChange(Uri uri) { if (holdNotifyChange) { synchronized (pendingNotifyChange) { pendingNotifyChange.add(uri); }/* w w w . j a v a 2 s. co m*/ } else { Context context = getContext(); if (context == null) { return; } context.getContentResolver().notifyChange(uri, null); if (MuzeiProvider.uriMatcher.match(uri) == ARTWORK || MuzeiProvider.uriMatcher.match(uri) == ARTWORK_ID) { context.sendBroadcast(new Intent(MuzeiContract.Artwork.ACTION_ARTWORK_CHANGED)); } else if (MuzeiProvider.uriMatcher.match(uri) == SOURCES || MuzeiProvider.uriMatcher.match(uri) == SOURCE_ID) { context.sendBroadcast(new Intent(MuzeiContract.Sources.ACTION_SOURCE_CHANGED)); } } }