List of usage examples for android.support.v4.content LocalBroadcastManager getInstance
public static LocalBroadcastManager getInstance(Context context)
From source file:com.aniruddhc.acemusic.player.Services.DashClockExtensionService.java
@Override public void onDestroy() { super.onDestroy(); LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver); }
From source file:ch.bfh.instacircle.service.NetworkService.java
@Override public void onDestroy() { // Stop everything if the leave message is coming from myself try {//from ww w . ja va 2 s . c o m for (int i = 0; i < tcpUnicastReceiverThreads.length; i++) { tcpUnicastReceiverThreads[i].interrupt(); udpBroadcastReceiverThreads[i].interrupt(); tcpUnicastReceiverThreads[i].serverSocket.close(); udpBroadcastReceiverThreads[i].socket.close(); } } catch (Exception e) { } dbHelper.closeConversation(); WifiManager wifiman = (WifiManager) getSystemService(Context.WIFI_SERVICE); new AdhocWifiManager(wifiman).restoreWifiConfiguration(getBaseContext()); WifiAPManager wifiAP = new WifiAPManager(); if (wifiAP.isWifiAPEnabled(wifiman)) { wifiAP.disableHotspot(wifiman, getBaseContext()); } stopSelf(); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); // Unregister the receiver which listens for messages to be sent LocalBroadcastManager.getInstance(this).unregisterReceiver(messageSendReceiver); // close the DB connection dbHelper.close(); super.onDestroy(); }
From source file:br.com.maracujas.classicrockwallpapersfinal.MyDownloadService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "onStartCommand:" + intent + ":" + startId); if (ACTION_DOWNLOAD.equals(intent.getAction())) { // Get the path to download from the intent final String downloadPath = intent.getStringExtra(EXTRA_DOWNLOAD_PATH); // Mark task started Log.d(TAG, ACTION_DOWNLOAD + ":" + downloadPath); taskStarted();//from ww w. j a v a 2s .c o m Log.d(TAG, mStorage.child(downloadPath).toString()); // Download and get total bytes mStorage.child(downloadPath).getStream() .addOnSuccessListener(new OnSuccessListener<StreamDownloadTask.TaskSnapshot>() { @Override public void onSuccess(StreamDownloadTask.TaskSnapshot taskSnapshot) { Log.d(TAG, "download:SUCCESS"); // Send success broadcast with number of bytes downloaded Intent broadcast = new Intent(ACTION_COMPLETED); broadcast.putExtra(EXTRA_DOWNLOAD_PATH, downloadPath); broadcast.putExtra(EXTRA_BYTES_DOWNLOADED, taskSnapshot.getTotalByteCount()); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(broadcast); // Mark task completed taskCompleted(); } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception exception) { Log.w(TAG, "download:FAILURE", exception); // Send failure broadcast Intent broadcast = new Intent(ACTION_ERROR); broadcast.putExtra(EXTRA_DOWNLOAD_PATH, downloadPath); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(broadcast); // Mark task completed taskCompleted(); } }); } return START_REDELIVER_INTENT; }
From source file:com.android.elixr.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {//from w w w . j a v a 2 s . co 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); // 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:android.demo.amitrai.gcmdemo.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {//from w ww . j a v 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); // 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.screenspeak.eventprocessor.ProcessorAccessibilityHints.java
public ProcessorAccessibilityHints(Context context, SpeechController speechController, CursorControllerApp cursorController) { if (speechController == null) throw new IllegalStateException(); mPrefs = PreferenceManager.getDefaultSharedPreferences(context); mContext = context;/*from w w w .j a va 2s .c o m*/ mSpeechController = speechController; mCursorController = cursorController; mRuleProcessor = NodeSpeechRuleProcessor.getInstance(); mHandler = new A11yHintHandler(this); mGestureActionMonitor.setListener(this); LocalBroadcastManager.getInstance(mContext).registerReceiver(mGestureActionMonitor, GestureActionMonitor.FILTER); }
From source file:com.android.gcm.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {/* ww w. jav a 2 s . com*/ // [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(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); // 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(); sharedPreferences.edit().putString("REGID", token).apply(); Log.i(TAG, sharedPreferences.getString("REGID", "BREH!!!!!!!!!!!!!!")); // [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:be.ehb.fallwear.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { Log.i(TAG, "GCM Registration handle"); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {//from w w w . java 2 s. c om // [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); 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(); sharedPreferences.edit().putString(QuickstartPreferences.TOKEN, token).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:azzaoui.sociadee.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {/*from w w w .ja v a2s.co 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_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(Parameters.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(Parameters.SENT_TOKEN_TO_SERVER, false).apply(); } // Notify UI that registration has completed, so the progress indicator can be hidden. Intent registrationComplete = new Intent(Parameters.REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); }
From source file:ch.luethi.skylinestracker.MainActivity.java
@Override protected void onPause() { super.onPause(); app.guiActive = false;/*from w w w. j a v a 2 s.c om*/ LocalBroadcastManager.getInstance(this).unregisterReceiver(onStatusChange); }