List of usage examples for android.support.v4.content LocalBroadcastManager getInstance
public static LocalBroadcastManager getInstance(Context context)
From source file:be.thomasave.executeorder42.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {/*from w w w . j a v a2 s .c o m*/ // In the (unlikely) event that multiple refresh operations occur simultaneously, // ensure that they are processed sequentially. synchronized (TAG) { // [START register_for_gcm] // Initially this call goes out to the network to retrieve the token, subsequent calls // are local. // [START get_token] InstanceID instanceID = InstanceID.getInstance(this); String token = instanceID.getToken("803737645614", 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); // 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:ca.appvelopers.mcgillmobile.ui.ebill.EbillActivity.java
/** * Refreshes the list of statements// ww w . j a va2 s .c om */ protected void refresh() { if (!canRefresh()) { return; } mcGillService.ebill().enqueue(new Callback<List<Statement>>() { @Override public void onResponse(Call<List<Statement>> call, Response<List<Statement>> response) { App.setEbill(response.body()); showToolbarProgress(false); update(); } @Override public void onFailure(Call<List<Statement>> call, Throwable t) { Timber.e(t, "Error refreshing the ebill"); showToolbarProgress(false); //If this is a MinervaException, broadcast it if (t instanceof MinervaException) { LocalBroadcastManager.getInstance(EbillActivity.this) .sendBroadcast(new Intent(Constants.BROADCAST_MINERVA)); } else { DialogHelper.error(EbillActivity.this, R.string.error_other); } } }); }
From source file:com.android.contacts.activities.RequestPermissionsActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { if (permissions != null && permissions.length > 0 && isAllGranted(permissions, grantResults)) { mPreviousActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); if (mIsCallerSelf) { startActivityForResult(mPreviousActivityIntent, 0); } else {// w ww . ja va2 s .c o m startActivity(mPreviousActivityIntent); } finish(); overridePendingTransition(0, 0); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(BROADCAST_PERMISSIONS_GRANTED)); } else { Toast.makeText(this, R.string.missing_required_permission, Toast.LENGTH_SHORT).show(); finish(); } }
From source file:com.afrolkin.samplepushclient.GCMIntentService.java
@Override protected void onMessage(Context arg0, Intent arg1) { // Retrieve push message value from "message" key from JSON formatted data // (For BlackBerry devices) The data sent from the server MUST BE FORMATTED AS JSON // For example, the data sent by the server for this app must be formatted as: // { "message":"value", key2: value2, "key3": value3, key4 : "value 4" } // In the following, we are only retrieving the data from the "message" key // If the message appears as "null" within the app, then the data sent by the server // was not formatted correctly final String message = arg1.getStringExtra("message"); Log.i(TAG, "New Push Message: " + message); Intent intent = new Intent(getString(R.string.push_message_action)); intent.putExtra(getString(R.string.push_message_extra), message); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); // Generate a system wide notification containing the push message generateNotification(arg0, message); }
From source file:asia.covisoft.goom.gcm.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {/*from ww w .j av a 2 s .c o m*/ // [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); Log.d("sdb", "GCM Registration Token: " + token); // TODO: Implement this method to send any registration to your app's servers. sendRegistrationToServer(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.nunes.sophiamobile.gsm.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); String token = ""; try {/* w ww .j a v a 2s. c om*/ // In the (unlikely) event that multiple refresh operations occur simultaneously, // ensure that they are processed sequentially. synchronized (TAG) { // [START register_for_gcm] // Initially this call goes out to the network to retrieve the token, subsequent calls // are local. // [START get_token] InstanceID instanceID = InstanceID.getInstance(this); token = instanceID.getToken(SENDER_ID, 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); // 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); sendRegistrationToServer(token); }
From source file:chat.mobilecomputationproject.utilities.RegistrationService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {/*from www .j a v a2 s . c o m*/ // [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); // 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(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(SENT_TOKEN_TO_SERVER, false).apply(); } // Notify UI that registration has completed, so the progress indicator can be hidden. Intent registrationComplete = new Intent(REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); }
From source file:com.amgems.uwschedule.services.LoginService.java
protected void onHandleIntent(Intent intent) { LoginAuthenticator command = LoginAuthenticator.newInstance(getApplicationContext(), new Handler(), new DefaultHttpClient(), intent.getStringExtra(PARAM_IN_USERNAME), intent.getStringExtra(PARAM_IN_PASSWORD)); command.execute();/* ww w .j ava 2 s . c o m*/ Response response = command.getResponse(); Intent broadcastIntent = new Intent(); LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this); broadcastIntent.setAction(ACTION_RESPONSE); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra(PARAM_OUT_RESPONSE, response); if (response == Response.OK) { broadcastIntent.putExtra(PARAM_OUT_COOKIE, command.getCookie().toString()); } broadcastManager.sendBroadcast(broadcastIntent); }
From source file:ch.bfh.instacircle.MessageSendFragment.java
public void onClick(View view) { if (view == btnSend) { et = (EditText) getActivity().findViewById(R.id.message_text); String identification = getActivity().getSharedPreferences(PREFS_NAME, 0).getString("identification", "N/A"); // create new message instance Message message = new Message(et.getText().toString(), Message.MSG_CONTENT, identification, dbHelper.getNextSequenceNumber()); Intent intent = new Intent("messageSend"); intent.putExtra("message", message); if (broadcast == false && ipAddress == null) { Log.w(TAG, "IP Address not set, cannot send unicast message"); } else if (broadcast == false) { // pass message to service using the local broacast manager intent.putExtra("ipAddress", ipAddress); intent.putExtra("broadcast", false); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent); } else {/* w ww. ja v a 2 s .co m*/ // pass message to service using the local broacast manager intent.putExtra("broadcast", true); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent); } // clear the textfield et.setText(""); } }
From source file:com.android.madpausa.cardnotificationviewer.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); if (sp.getBoolean(SettingsActivityFragment.TEST_MODE, false)) setContentView(R.layout.activity_main_test); else/*from w w w. j a v a 2 s . c o m*/ setContentView(R.layout.activity_main); //binding the service Intent intent = new Intent(this, ConcreteNotificationListenerService.class); intent.setAction(ConcreteNotificationListenerService.CUSTOM_BINDING); bindService(intent, nConnection, Context.BIND_AUTO_CREATE); nReceiver = new NotificationReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction(ConcreteNotificationListenerService.ADD_NOTIFICATION_ACTION); filter.addAction(ConcreteNotificationListenerService.REMOVE_NOTIFICATION_ACTION); filter.addAction(NotificationDialogFragment.NOTIFICATION_DIALOG_INTENT); LocalBroadcastManager.getInstance(this).registerReceiver(nReceiver, filter); nFragment = (MainActivityFragment) getSupportFragmentManager().findFragmentById(R.id.fragment); }