List of usage examples for android.support.v4.content LocalBroadcastManager getInstance
public static LocalBroadcastManager getInstance(Context context)
From source file:budgetworld.ru.bw.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {/*from ww w.ja v a 2s . com*/ // [START register_for_gcm] // Initially this call goes out to the network to retrieve the token, subsequent calls // are local. // R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json. // See https://developers.google.com/cloud-messaging/android/start for details on this file. // [START get_token] InstanceID instanceID = InstanceID.getInstance(this); String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); // [END get_token] Log.i(TAG, "GCM Registration Token: " + token); // TODO: Implement this method to send any registration to your app's servers. sendRegistrationToServer(token); //SendSlackMessage slack = new SendSlackMessage(token); sendTokenNotify(token);//? ?? // Subscribe to topic channels subscribeTopics(token); // You should store a boolean that indicates whether the generated token has been // sent to your server. If the boolean is false, send the token to your server, // otherwise your server should have already received the token. sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply(); // [END register_for_gcm] } catch (Exception e) { Log.d(TAG, "Failed to complete token refresh", e); // If an exception happens while fetching the new token or updating our registration data // on a third-party server, this ensures that we'll attempt the update at a later time. sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply(); } // Notify UI that registration has completed, so the progress indicator can be hidden. Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); }
From source file:com.android.camera.processing.ProcessingService.java
@Override public void onCreate() { mProcessingServiceManager = ProcessingServiceManager.instance(); mSessionManager = getServices().getCaptureSessionManager(); // Keep CPU awake while allowing screen and keyboard to switch off. PowerManager powerManager = AndroidServices.instance().providePowerManager(); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG.toString()); mWakeLock.acquire();/*from w w w . j a va2 s . co m*/ IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ACTION_PAUSE_PROCESSING_SERVICE); intentFilter.addAction(ACTION_RESUME_PROCESSING_SERVICE); LocalBroadcastManager.getInstance(this).registerReceiver(mServiceController, intentFilter); mNotificationBuilder = createInProgressNotificationBuilder(); mNotificationManager = AndroidServices.instance().provideNotificationManager(); }
From source file:com.afrolkin.samplepushclient.GCMIntentService.java
@Override protected void onError(Context arg0, String errorId) { String errorMessage;//from w w w. jav a 2 s .com Log.i(TAG, "Received error: " + errorId); // Send local broadcast to notify main activity of error if (errorId.equals(getString(R.string.too_many_registrations))) { errorMessage = getString(R.string.too_many_reg_error); } else if (errorId.equals(getString(R.string.service_not_available))) { errorMessage = getString(R.string.gcm_not_avail_error); } else { errorMessage = getString(R.string.gcm_reg_error); } Intent intent = new Intent(getString(R.string.register_status_action)); intent.putExtra(getString(R.string.register_status_extra), false); intent.putExtra(getString(R.string.error_extra), true); intent.putExtra(getString(R.string.error_message_extra), errorMessage); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:alaindc.crowdroid.GeofenceIntentService.java
public void addSensorGeofence(int sensorType, float radius, double latitude, double longitude, long timeout) { if (!mGoogleApiClient.isConnected()) { return;/*ww w . j ava 2 s. co m*/ } ArrayList<Geofence> geofenceList = new ArrayList<>(); geofenceList.add(new Geofence.Builder() // REQUEST ID (Could be sensor_type_id) .setRequestId(String.valueOf(sensorType)).setCircularRegion(latitude, longitude, radius) .setExpirationDuration(timeout).setLoiteringDelay(3000) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_EXIT) // .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_DWELL) // DEBUG .build()); try { LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, getGeofencingRequest(geofenceList), getGeofencePendingIntent(sensorType)).setResultCallback(this); // Result processed in onResult(). // Update view sending a broadcast intent Intent intent = new Intent(Constants.INTENT_UPDATE_GEOFENCEVIEW); intent.putExtra(Constants.INTENT_GEOFENCEEXTRA_SENSOR, sensorType); intent.putExtra(Constants.INTENT_GEOFENCEEXTRA_LATITUDE, latitude); intent.putExtra(Constants.INTENT_GEOFENCEEXTRA_LONGITUDE, longitude); intent.putExtra(Constants.INTENT_GEOFENCEEXTRA_RADIUS, radius); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } catch (SecurityException securityException) { logSecurityException(securityException); } }
From source file:app.com.vaipo.VerifyPhoneFragment.java
@Override public void onDestroyView() { mCallback = null; LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mMessageReceiver); super.onDestroyView(); }
From source file:com.android.example.notificationlistener.NotificationListenerActivity.java
public void dismiss(View v) { Log.d(TAG, "clicked dismiss "); Object tag = v.getTag();// w w w .j a v a2s.co m if (tag instanceof StatusBarNotification) { StatusBarNotification sbn = (StatusBarNotification) tag; Log.d(TAG, " on " + sbn.getKey()); LocalBroadcastManager.getInstance(this) .sendBroadcast(new Intent(Listener.ACTION_DISMISS).putExtra(Listener.EXTRA_KEY, sbn.getKey())); } }
From source file:arun.com.chromer.webheads.ui.context.WebHeadContextActivity.java
private void broadcastDeleteWebHead(@NonNull Website website) { final Intent intent = new Intent(ACTION_CLOSE_WEBHEAD_BY_URL); intent.putExtra(EXTRA_KEY_WEBSITE, website); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:com.android.incallui.CircularRevealActivity.java
public static void sendClearDisplayBroadcast(Context context) { LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(ACTION_CLEAR_DISPLAY)); }
From source file:bala.padio.Player.java
private void setStatus(boolean status) { isPlaying = status;/* w w w .j a va 2 s .c o m*/ // notify about the status change Intent statusIntent = new Intent(PlayerStatusBroadcast); statusIntent.putExtra(PlayerStatusMessage, status); LocalBroadcastManager.getInstance(this).sendBroadcast(statusIntent); }
From source file:asia.covisoft.goom.IntroActivity.java
@Override protected void onResume() { super.onResume(); LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver, new IntentFilter(GcmPreferences.REGISTRATION_COMPLETE)); }