List of usage examples for android.content Context sendBroadcast
public abstract void sendBroadcast(@RequiresPermission Intent intent);
From source file:com.mfcoding.locationBP.receivers.LocationChangedReceiver.java
/** * When a new location is received, extract it from the Intent and use * it to start the Service used to update the list of nearby places. * //from w w w. j a va 2 s . c o m * This is the Active receiver, used to receive Location updates when * the Activity is visible. */ @Override public void onReceive(Context context, Intent intent) { String locationKey = LocationManager.KEY_LOCATION_CHANGED; String providerEnabledKey = LocationManager.KEY_PROVIDER_ENABLED; if (intent.hasExtra(providerEnabledKey)) { if (!intent.getBooleanExtra(providerEnabledKey, true)) { Intent providerDisabledIntent = new Intent( PlacesConstants.ACTIVE_LOCATION_UPDATE_PROVIDER_DISABLED); context.sendBroadcast(providerDisabledIntent); } } if (intent.hasExtra(locationKey)) { Location location = (Location) intent.getExtras().get(locationKey); Log.d(TAG, "Actively Updating location lat:" + location.getLatitude() + " lng:" + location.getLongitude()); Intent updateServiceIntent = new Intent(context, PlacesConstants.SUPPORTS_ECLAIR ? EclairPlacesUpdateService.class : LocationUpdateService.class); updateServiceIntent.putExtra(PlacesConstants.EXTRA_KEY_LOCATION, location); updateServiceIntent.putExtra(PlacesConstants.EXTRA_KEY_RADIUS, PlacesConstants.DEFAULT_RADIUS); updateServiceIntent.putExtra(PlacesConstants.EXTRA_KEY_FORCEREFRESH, true); context.startService(updateServiceIntent); // Intent locUpdateIntent = new Intent(PlacesConstants.ACTIVE_LOCATION_UPDATE); // context.sendBroadcast(locUpdateIntent); } }
From source file:com.lvlstudios.android.gtmessage.DeviceRegistrar.java
public static void registerWithServer(final Context context, final String deviceRegistrationID) { new Thread(new Runnable() { @Override// w w w . ja va2 s . c o m public void run() { // Success/failure to be displayed on Setup screens. Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI"); try { // Make the request to our server to save the registration id. HttpResponse res = makeRequest(context, deviceRegistrationID, REGISTER_PATH); if (res.getStatusLine().getStatusCode() == 200) { // Save registration id to preferences SharedPreferences settings = Prefs.get(context); SharedPreferences.Editor editor = settings.edit(); editor.putString("deviceRegistrationID", deviceRegistrationID); editor.commit(); 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) { // Get setup activity to ask permission from user. Intent intent = new Intent(SetupActivity.AUTH_PERMISSION_ACTION); intent.putExtra("AccountManagerBundle", pae.getAccountManagerBundle()); context.sendBroadcast(intent); } catch (Exception e) { Log.w(TAG, "Registration error " + e.getMessage()); updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS); context.sendBroadcast(updateUIIntent); } } }).start(); }
From source file:org.herrlado.websms.connector.magtifunge.ConnectorMagtifun.java
/** * Load captcha and wait for user input to solve it. * /*from ww w. j ava2 s .com*/ * @param second * * @param context * {@link Context} * @param flow * _flowExecutionKey * @return true if captcha was solved * @throws IOException * IOException */ private String solveCaptcha(final ConnectorContext ctx, String body) throws IOException { String url = URL_CAPTCHA; String num = findCaptchaNum(body); if (TextUtils.isEmpty(num) == false) { url = url + num; } else { url = url + DEFAULT_URL_CAPTCHA_PARAMETER; } HttpGet cap = new HttpGet(url); cap.addHeader("Referer", "http://www.magtifun.ge/index.php?page=2&lang=ge"); cap.setHeader("User-Agent", FAKE_USER_AGENT); HttpResponse response = ctx.getClient().execute(cap); int resp = response.getStatusLine().getStatusCode(); if (resp != HttpURLConnection.HTTP_OK) { throw new WebSMSException(ctx.getContext(), 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; Context context = ctx.getContext(); 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 null; } if (captchaSolve == null) { return captchaSolve; } // got user response, try to solve captcha Log.d(TAG, "got solved captcha: " + captchaSolve); return captchaSolve; }
From source file:com.example.hack_push.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras();//from w w w . j ava2 s .c o m String message = extras.getString("message"); ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); Intent intent_sendback = new Intent(MainActivity.DISPLAY_MESSAGE_ACTION); intent_sendback.putExtra("message", message); context.sendBroadcast(intent_sendback); }
From source file:com.mattprecious.prioritysms.receiver.AlarmReceiver.java
private void doAlarm(Context context, BaseProfile profile, String number, String message) { // Maintain a cpu wake lock until the AlarmActivity and AlarmService can // pick it up. AlarmAlertWakeLock.acquireCpuWakeLock(context); /* Close dialogs and window shade */ Intent closeDialogs = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); context.sendBroadcast(closeDialogs); // Play the alarm alert and vibrate the device. Intent playAlarm = new Intent(Intents.ACTION_ALERT); playAlarm.putExtra(Intents.EXTRA_PROFILE, profile); context.startService(playAlarm);/*from w w w .j ava2 s . c om*/ Intent dismissIntent = new Intent(Intents.ACTION_DISMISS); dismissIntent.putExtra(Intents.EXTRA_PROFILE, profile); PendingIntent pendingDismiss = PendingIntent.getBroadcast(context, profile.getId(), dismissIntent, 0); Intent replyIntent = new Intent(Intents.ACTION_REPLY); replyIntent.putExtra(Intents.EXTRA_PROFILE, profile); PendingIntent pendingReply = PendingIntent.getBroadcast(context, profile.getId(), replyIntent, 0); Intent callIntent = new Intent(Intents.ACTION_CALL); callIntent.putExtra(Intents.EXTRA_PROFILE, profile); PendingIntent pendingCall = PendingIntent.getBroadcast(context, profile.getId(), callIntent, 0); Intent activityIntent = new Intent(context, AlarmActivity.class); activityIntent.setAction(String.valueOf(System.currentTimeMillis())); activityIntent.putExtra(Intents.EXTRA_PROFILE, profile); activityIntent.putExtra(Intents.EXTRA_NUMBER, number); activityIntent.putExtra(Intents.EXTRA_MESSAGE, message); activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); PendingIntent pendingActivity = PendingIntent.getActivity(context, profile.getId(), activityIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentTitle(profile.getName()).setSmallIcon(R.drawable.ic_stat_alarm).setAutoCancel(false) .setPriority(NotificationCompat.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS) .addAction(android.R.drawable.ic_menu_close_clear_cancel, context.getString(R.string.notif_action_dismiss), pendingDismiss) .addAction(android.R.drawable.ic_menu_send, context.getString(R.string.notif_action_reply), pendingReply) .addAction(android.R.drawable.ic_menu_call, context.getString(R.string.notif_action_call), pendingCall) .setFullScreenIntent(pendingActivity, true).setContentIntent(pendingActivity) .setDeleteIntent(pendingDismiss); Notification notif = builder.build(); // Send the notification using the alarm id to easily identify the // correct notification. NotificationManager nm = getNotificationManager(context); nm.notify(profile.getId(), notif); // full screen intent doesn't do anything pre-honeycomb if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { context.startActivity(activityIntent); } }
From source file:io.rapidpro.androidchannel.HomeActivity.java
public void updateClaimCode(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String secret = prefs.getString(SettingsActivity.RELAYER_CLAIM_CODE, null); Intent intent = new Intent(UPDATE_RELAYER_STATE); intent.putExtra(CLAIM_CODE_EXTRA, secret); context.sendBroadcast(intent); }
From source file:com.drinviewer.droiddrinviewer.DrinViewerBroadcastReceiver.java
/** * Stops the alarm repeater after a disconnection from a WiFi network * /*from w w w.j a v a 2 s.c o m*/ * @param context The context to use */ private void stopAlarmRepeater(Context context) { /** * Sends a message to clean the host collection, and stop the DiscoverServerService * should be safe because this method gets called on WiFi disconnect */ Intent i = new Intent(context, this.getClass()); i.setAction(context.getResources().getString(R.string.broadcast_cleanhostcollection)); i.putExtra("stopservice", true); context.sendBroadcast(i); /** * Cancel the pending intent from the AlarmManager */ PendingIntent senderstop = PendingIntent.getBroadcast(context, 0, new Intent(context, this.getClass()), 0); // Get the alarm manager if (alarmManager == null) alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(senderstop); }
From source file:com.androidinspain.deskclock.alarms.AlarmStateManager.java
/** * Used in pre-L devices, where "next alarm" is stored in system settings. *///from w ww . j a v a2s .c om @SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.KITKAT) private static void updateNextAlarmInSystemSettings(Context context, AlarmInstance nextAlarm) { // Format the next alarm time if an alarm is scheduled. String time = ""; if (nextAlarm != null) { time = AlarmUtils.getFormattedTime(context, nextAlarm.getAlarmTime()); } try { // Write directly to NEXT_ALARM_FORMATTED in all pre-L versions Settings.System.putString(context.getContentResolver(), NEXT_ALARM_FORMATTED, time); LogUtils.i("Updated next alarm time to: \'" + time + '\''); // Send broadcast message so pre-L AppWidgets will recognize an update. context.sendBroadcast(new Intent(ACTION_ALARM_CHANGED)); } catch (SecurityException se) { // The user has most likely revoked WRITE_SETTINGS. LogUtils.e("Unable to update next alarm to: \'" + time + '\'', se); } }
From source file:com.notifry.android.C2DMReceiver.java
public void onError(Context context, String errorId) { // Store this for later. Log.e("Notifry", "Error with registration: " + errorId); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); Editor editor = settings.edit();//from www. j a va 2 s .c o m editor.putString("dm_register_error", errorId); editor.commit(); // Notify the user. // TODO: Do this. // Update the home screen. Intent updateUIIntent = new Intent(Notifry.UPDATE_INTENT); context.sendBroadcast(updateUIIntent); }
From source file:com.saulcintero.moveon.services.MediaButtonEventReceiver.java
@Override public void onReceive(Context mContext, Intent intent) { String intentAction = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) return; if (event.getAction() == KeyEvent.ACTION_UP) { Intent i = new Intent("android.intent.action.ACTION_SAY_PRACTICE_INFORMATION"); i.putExtra("type", String.valueOf(NotificationTypes.TIME.getTypes())); mContext.sendBroadcast(i); }/*from www . j ava2s. c o m*/ } }