List of usage examples for android.support.v4.content LocalBroadcastManager getInstance
public static LocalBroadcastManager getInstance(Context context)
From source file:ch.bfh.instacircle.service.NetworkService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { // Initializing the dbHelper in order to get access to the database dbHelper = NetworkDbHelper.getInstance(this); // Create a pending intent which will be invoked after tapping on the // Android notification Intent notificationIntent = new Intent(this, NetworkActiveActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME); PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, notificationIntent.getFlags()); // Setting up the notification which is being displayed Notification.Builder notificationBuilder = new Notification.Builder(this); notificationBuilder.setContentTitle(getResources().getString(R.string.app_name)); notificationBuilder.setContentText("An InstaCircle Chat session is running. Tap to bring in front."); notificationBuilder.setSmallIcon(R.drawable.glyphicons_244_conversation); notificationBuilder.setContentIntent(pendingNotificationIntent); notificationBuilder.setOngoing(true); Notification notification = notificationBuilder.getNotification(); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(TAG, 1, notification); udpBroadcastReceiverThreads = new UDPBroadcastReceiverThread[100]; tcpUnicastReceiverThreads = new TCPUnicastReceiverThread[100]; // starting 100 threads allocating 100 Ports for (int i = 0; i < 50; i++) { udpBroadcastReceiverThreads[i] = new UDPBroadcastReceiverThread(this, i + 12300); tcpUnicastReceiverThreads[i] = new TCPUnicastReceiverThread(this, i + 12300); udpBroadcastReceiverThreads[i].start(); tcpUnicastReceiverThreads[i].start(); }/*from ww w .java2 s. co m*/ // Register a broadcastreceiver in order to get notification from the UI // when a message should be sent LocalBroadcastManager.getInstance(this).registerReceiver(messageSendReceiver, new IntentFilter("messageSend")); // Opening a conversation dbHelper.openConversation(getSharedPreferences(PREFS_NAME, 0).getString("password", "N/A")); // joining the conversation using the identification in the preferences // file joinNetwork(getSharedPreferences(PREFS_NAME, 0).getString("identification", "N/A")); // start the NetworkActiveActivity intent = new Intent(this, NetworkActiveActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME); startActivity(intent); return super.onStartCommand(intent, flags, startId); }
From source file:com.achep.acdisplay.services.BathService.java
@Override public void onCreate() { super.onCreate(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mLanguage = getResources().getConfiguration().locale.getLanguage(); // Listen for the config changes to update notification just // once locale has changed. IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); registerReceiver(mReceiver, intentFilter); synchronized (monitor) { sCreated = true;/*from w w w. j av a 2 s .c o m*/ // Register for add / remove service events. intentFilter = new IntentFilter(); intentFilter.addAction(ACTION_ADD_SERVICE); intentFilter.addAction(ACTION_REMOVE_SERVICE); mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); mLocalBroadcastManager.registerReceiver(mReceiver, intentFilter); if (sServiceMap.isEmpty()) { stopSelf(); } else { // Init all children Set<Map.Entry<Class, ChildService>> set = sServiceMap.entrySet(); for (Map.Entry<Class, ChildService> entry : set) { ChildService child = entry.getValue(); child.setContext(this); child.onCreate(); mMap.put(entry.getKey(), child); } sServiceMap.clear(); startForeground(App.ID_NOTIFY_BATH, buildNotification()); } } }
From source file:com.android.camera.ActivityBase.java
@Override protected void onResume() { super.onResume(); LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this); manager.registerReceiver(mDeletePictureReceiver, mDeletePictureFilter); }
From source file:com.android.fpuna.activityrecognition.MainActivity.java
@Override protected void onResume() { super.onResume(); // Register the broadcast receiver that informs this activity of the DetectedActivity // object broadcast sent by the intent service. LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, new IntentFilter(Constants.BROADCAST_ACTION)); }
From source file:com.android.talkback.tutorial.TutorialLessonFragment.java
@Override public void onResume() { super.onResume(); Activity activity = getActivity();/* w w w . j a v a2s. co m*/ if (activity != null) { ActionBar actionBar = activity.getActionBar(); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowCustomEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setCustomView(R.layout.tutorial_action_bar); actionBar.getCustomView().findViewById(R.id.up).setOnClickListener(this); TextView title = (TextView) actionBar.getCustomView().findViewById(R.id.action_bar_title); title.setText(getTitle()); LocalBroadcastManager.getInstance(activity).registerReceiver(mActionMonitor, GestureActionMonitor.FILTER); } TalkBackService service = TalkBackService.getInstance(); if (service != null) { service.addEventListener(mExercise); } }
From source file:cloud.artik.example.simplecontroller.ArtikCloudSession.java
private void createFirehoseWebsocket() { try {/*w ww . ja va 2 s . co m*/ mFirehoseWS = new FirehoseWebSocket(mAccessToken, DEVICE_ID, null, null, null, new ArtikCloudWebSocketCallback() { @Override public void onOpen(int i, String s) { Log.d(TAG, "FirehoseWebSocket: onOpen()"); final Intent intent = new Intent(WEBSOCKET_LIVE_ONOPEN); LocalBroadcastManager.getInstance(ourContext).sendBroadcast(intent); } @Override public void onMessage(MessageOut messageOut) { Log.d(TAG, "FirehoseWebSocket: onMessage(" + messageOut.toString() + ")"); final Intent intent = new Intent(WEBSOCKET_LIVE_ONMSG); intent.putExtra(SDID, messageOut.getSdid()); intent.putExtra(DEVICE_DATA, messageOut.getData().toString()); intent.putExtra(TIMESTEP, messageOut.getTs().toString()); LocalBroadcastManager.getInstance(ourContext).sendBroadcast(intent); } @Override public void onAction(ActionOut actionOut) { } @Override public void onAck(Acknowledgement acknowledgement) { } @Override public void onClose(int code, String reason, boolean remote) { final Intent intent = new Intent(WEBSOCKET_LIVE_ONCLOSE); intent.putExtra("error", "mFirehoseWS is closed. code: " + code + "; reason: " + reason); LocalBroadcastManager.getInstance(ourContext).sendBroadcast(intent); } @Override public void onError(WebSocketError ex) { final Intent intent = new Intent(WEBSOCKET_LIVE_ONERROR); intent.putExtra("error", "mFirehoseWS error: " + ex.getMessage()); LocalBroadcastManager.getInstance(ourContext).sendBroadcast(intent); } @Override public void onPing(long timestamp) { Log.d(TAG, "FirehoseWebSocket::onPing: " + timestamp); } }); } catch (URISyntaxException | IOException e) { e.printStackTrace(); } }
From source file:cc.softwarefactory.lokki.android.activities.MainActivity.java
@Override protected void onPause() { super.onPause(); LocationService.stop(this.getApplicationContext()); DataService.stop(this.getApplicationContext()); LocalBroadcastManager.getInstance(this).unregisterReceiver(switchToMapReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(exitMessageReceiver); }
From source file:com.amazon.android.contentbrowser.helper.AuthHelper.java
/** * Constructor.//ww w. ja v a2 s . c o m * * @param context Context. * @param contentBrowser Content browser. */ public AuthHelper(Context context, ContentBrowser contentBrowser) { mAppContext = context.getApplicationContext(); mContentBrowser = contentBrowser; // Get default Auth interface without creating a new one. try { mIAuthentication = (IAuthentication) ModuleManager.getInstance() .getModule(IAuthentication.class.getSimpleName()).getImpl(true); } catch (Exception e) { Log.e(TAG, "No Auth Interface interface attached.", e); } IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(LogoutSettingsFragment.LOGOUT_BUTTON_BROADCAST_INTENT_ACTION); LocalBroadcastManager.getInstance(mAppContext).registerReceiver(mLocalBroadcastReceiver, intentFilter); //AuthHelper is initialized, broadcast initial authentication status isAuthenticated().subscribe(isAuthenticatedResultBundle -> { boolean result = isAuthenticatedResultBundle.getBoolean(AuthHelper.RESULT); broadcastAuthenticationStatus(result); }); }
From source file:ca.hoogit.garagepi.Controls.DoorControlService.java
private void broadcastToggleEvent(boolean toggled, String name) { Intent intent = new Intent(Consts.INTENT_MESSAGE_DOORS); intent.putExtra(Consts.KEY_BROADCAST_ACTION, Consts.ACTION_DOORS_TOGGLE); intent.putExtra(Consts.KEY_BROADCAST_SUCCESS, toggled); intent.putExtra(Consts.KEY_DOOR_ID, name); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:ca.farrelltonsolar.classic.DayLogChart.java
private void unRegisterReceiver() { if (isReceiverRegistered) { try {//from ww w . java 2 s. c o m LocalBroadcastManager.getInstance(DayLogChart.this.getActivity()) .unregisterReceiver(mReadingsReceiver); } catch (IllegalArgumentException e) { // Do nothing } isReceiverRegistered = false; } }