List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:is.hello.buruberi.bluetooth.stacks.android.NativeBluetoothStack.java
@Override @RequiresPermission(allOf = { Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN, }) public Observable<Void> turnOff() { if (adapter == null) { return Observable.error(new ChangePowerStateException()); }//from www .ja va 2 s . c o m final ReplaySubject<Void> turnOnMirror = ReplaySubject.createWithSize(1); final BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final int oldState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, BluetoothAdapter.ERROR); final int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); if (oldState == BluetoothAdapter.STATE_ON && newState == BluetoothAdapter.STATE_TURNING_OFF) { logger.info(LOG_TAG, "Bluetooth turning off"); } else if (oldState == BluetoothAdapter.STATE_TURNING_OFF && newState == BluetoothAdapter.STATE_OFF) { logger.info(LOG_TAG, "Bluetooth turned off"); applicationContext.unregisterReceiver(this); turnOnMirror.onNext(null); turnOnMirror.onCompleted(); } else { logger.info(LOG_TAG, "Bluetooth failed to turn off"); applicationContext.unregisterReceiver(this); turnOnMirror.onError(new ChangePowerStateException()); } } }; applicationContext.registerReceiver(receiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)); if (!adapter.disable()) { applicationContext.unregisterReceiver(receiver); return Observable.error(new ChangePowerStateException()); } return turnOnMirror; }
From source file:com.zentri.zentri_ble_command_demo.MainActivity.java
private void initBroadcastReceiver() { mBroadcastReceiver = new BroadcastReceiver() { @Override/* w ww. j av a 2 s .c o m*/ public void onReceive(Context context, Intent intent) { // Get extra data included in the Intent String action = intent.getAction(); switch (action) { case ZentriOSBLEService.ACTION_SCAN_RESULT: String name = ZentriOSBLEService.getData(intent); //dont show devices with no name (mac addresses) if (name != null && !Pattern.matches(PATTERN_MAC_ADDRESS, name)) { addDeviceToList(name); } break; case ZentriOSBLEService.ACTION_CONNECTED: String deviceName = ZentriOSBLEService.getData(intent); mConnected = true; mHandler.removeCallbacks(mConnectTimeoutTask);//cancel timeout timer dismissDialog(mConnectProgressDialog); showToast("Connected to " + deviceName, Toast.LENGTH_SHORT); Log.d(TAG, "Connected to " + deviceName); startDeviceInfoActivity(); break; case ZentriOSBLEService.ACTION_DISCONNECTED: mConnected = false; break; case ZentriOSBLEService.ACTION_ERROR: ErrorCode errorCode = ZentriOSBLEService.getErrorCode(intent); //handle errors if (errorCode == ErrorCode.CONNECT_FAILED) { if (!mConnected && mConnecting) { mConnecting = false;//allow another attempt to connect dismissDialog(mConnectProgressDialog); } else { mConnected = false; } showErrorDialog(R.string.con_err_message, false); } break; } } }; }
From source file:hochschuledarmstadt.photostream_tools.PhotoStreamClientImpl.java
void bootstrap() { internetAvailableBroadcastReceiver = new BroadcastReceiver() { @Override//from w w w . jav a2 s . co m public void onReceive(Context context, Intent intent) { if (webSocketClient != null) { if (isOnline() && !webSocketClient.isConnected()) webSocketClient.connect(); else if (!isOnline()) { webSocketClient.destroy(); } } } }; if (webSocketClient != null) { webSocketClient.setMessageListener(this); webSocketClient.connect(); } new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { registerInternetAvailableBroadcastReceiver(); } }, 2000); }
From source file:de.lespace.apprtc.ConnectActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_connect); // Get setting keys. PreferenceManager.setDefaultValues(this, R.xml.preferences, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); keyprefFrom = getString(R.string.pref_from_key); keyprefVideoCallEnabled = getString(R.string.pref_videocall_key); keyprefResolution = getString(R.string.pref_resolution_key); keyprefFps = getString(R.string.pref_fps_key); keyprefCaptureQualitySlider = getString(R.string.pref_capturequalityslider_key); keyprefVideoBitrateType = getString(R.string.pref_startvideobitrate_key); keyprefVideoBitrateValue = getString(R.string.pref_startvideobitratevalue_key); keyprefVideoCodec = getString(R.string.pref_videocodec_key); keyprefHwCodecAcceleration = getString(R.string.pref_hwcodec_key); keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key); keyprefAudioBitrateType = getString(R.string.pref_startaudiobitrate_key); keyprefAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key); keyprefAudioCodec = getString(R.string.pref_audiocodec_key); keyprefNoAudioProcessingPipeline = getString(R.string.pref_noaudioprocessing_key); keyprefAecDump = getString(R.string.pref_aecdump_key); keyprefOpenSLES = getString(R.string.pref_opensles_key); keyprefDisplayHud = getString(R.string.pref_displayhud_key); keyprefTracing = getString(R.string.pref_tracing_key); keyprefRoomServerUrl = getString(R.string.pref_room_server_url_key); keyprefRoom = getString(R.string.pref_room_key); keyprefRoomList = getString(R.string.pref_room_list_key); from = sharedPref.getString(keyprefFrom, getString(R.string.pref_from_default)); // String roomUrl = sharedPref.getString( // keyprefRoomServerUrl, getString(R.string.pref_room_server_url_default)); // Video call enabled flag. boolean videoCallEnabled = sharedPref.getBoolean(keyprefVideoCallEnabled, Boolean.valueOf(getString(R.string.pref_videocall_default))); // Get default codecs. String videoCodec = sharedPref.getString(keyprefVideoCodec, getString(R.string.pref_videocodec_default)); String audioCodec = sharedPref.getString(keyprefAudioCodec, getString(R.string.pref_audiocodec_default)); // Check HW codec flag. boolean hwCodec = sharedPref.getBoolean(keyprefHwCodecAcceleration, Boolean.valueOf(getString(R.string.pref_hwcodec_default))); // Check Capture to texture. boolean captureToTexture = sharedPref.getBoolean(keyprefCaptureToTexture, Boolean.valueOf(getString(R.string.pref_capturetotexture_default))); // Check Disable Audio Processing flag. boolean noAudioProcessing = sharedPref.getBoolean(keyprefNoAudioProcessingPipeline, Boolean.valueOf(getString(R.string.pref_noaudioprocessing_default))); // Check Disable Audio Processing flag. boolean aecDump = sharedPref.getBoolean(keyprefAecDump, Boolean.valueOf(getString(R.string.pref_aecdump_default))); // Check OpenSL ES enabled flag. boolean useOpenSLES = sharedPref.getBoolean(keyprefOpenSLES, Boolean.valueOf(getString(R.string.pref_opensles_default))); // Check for mandatory permissions. int counter = 0; missingPermissions = new ArrayList(); for (String permission : MANDATORY_PERMISSIONS) { if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { counter++;//from w w w . j a v a 2s. com missingPermissions.add(permission); } } requestPermission(); // mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); gcmRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // mRegistrationProgressBar.setVisibility(ProgressBar.GONE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); if (sentToken) { logAndToast(getString(R.string.gcm_send_message)); // mInformationTextView.setText(getString(R.string.gcm_send_message)); } else { logAndToast(getString(R.string.gcm_send_message)); // mInformationTextView.setText(getString(R.string.token_error_message)); } } }; //Bring Call2Front when bringToFrontBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Intent intentStart = new Intent(getApplicationContext(), ConnectActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); intent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); startActivity(intentStart); // newFragment.show(transaction,"loading"); // showDialog(); } }; // Registering BroadcastReceiver registerGCMReceiver(); registerBringToFrontReceiver(); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } // Get video resolution from settings. int videoWidth = 0; int videoHeight = 0; String resolution = sharedPref.getString(keyprefResolution, getString(R.string.pref_resolution_default)); String[] dimensions = resolution.split("[ x]+"); if (dimensions.length == 2) { try { videoWidth = Integer.parseInt(dimensions[0]); videoHeight = Integer.parseInt(dimensions[1]); } catch (NumberFormatException e) { videoWidth = 0; videoHeight = 0; Log.e(TAG, "Wrong video resolution setting: " + resolution); } } // Get camera fps from settings. int cameraFps = 0; String fps = sharedPref.getString(keyprefFps, getString(R.string.pref_fps_default)); String[] fpsValues = fps.split("[ x]+"); if (fpsValues.length == 2) { try { cameraFps = Integer.parseInt(fpsValues[0]); } catch (NumberFormatException e) { Log.e(TAG, "Wrong camera fps setting: " + fps); } } // Check capture quality slider flag. boolean captureQualitySlider = sharedPref.getBoolean(keyprefCaptureQualitySlider, Boolean.valueOf(getString(R.string.pref_capturequalityslider_default))); // Get video and audio start bitrate. int videoStartBitrate = 0; String bitrateTypeDefault = getString(R.string.pref_startvideobitrate_default); String bitrateType = sharedPref.getString(keyprefVideoBitrateType, bitrateTypeDefault); if (!bitrateType.equals(bitrateTypeDefault)) { String bitrateValue = sharedPref.getString(keyprefVideoBitrateValue, getString(R.string.pref_startvideobitratevalue_default)); videoStartBitrate = Integer.parseInt(bitrateValue); } int audioStartBitrate = 0; bitrateTypeDefault = getString(R.string.pref_startaudiobitrate_default); bitrateType = sharedPref.getString(keyprefAudioBitrateType, bitrateTypeDefault); if (!bitrateType.equals(bitrateTypeDefault)) { String bitrateValue = sharedPref.getString(keyprefAudioBitrateValue, getString(R.string.pref_startaudiobitratevalue_default)); audioStartBitrate = Integer.parseInt(bitrateValue); } // Check statistics display option. boolean displayHud = sharedPref.getBoolean(keyprefDisplayHud, Boolean.valueOf(getString(R.string.pref_displayhud_default))); boolean tracing = sharedPref.getBoolean(keyprefTracing, Boolean.valueOf(getString(R.string.pref_tracing_default))); Log.d(TAG, "Connecting from " + from + " at URL " + Configs.ROOM_URL); if (validateUrl(Configs.ROOM_URL)) { Uri uri = Uri.parse(Configs.ROOM_URL); intent = new Intent(this, ConnectActivity.class); intent.setData(uri); intent.putExtra(CallActivity.EXTRA_VIDEO_CALL, videoCallEnabled); intent.putExtra(CallActivity.EXTRA_VIDEO_WIDTH, videoWidth); intent.putExtra(CallActivity.EXTRA_VIDEO_HEIGHT, videoHeight); intent.putExtra(CallActivity.EXTRA_VIDEO_FPS, cameraFps); intent.putExtra(CallActivity.EXTRA_VIDEO_CAPTUREQUALITYSLIDER_ENABLED, captureQualitySlider); intent.putExtra(CallActivity.EXTRA_VIDEO_BITRATE, videoStartBitrate); intent.putExtra(CallActivity.EXTRA_VIDEOCODEC, videoCodec); intent.putExtra(CallActivity.EXTRA_HWCODEC_ENABLED, hwCodec); intent.putExtra(CallActivity.EXTRA_CAPTURETOTEXTURE_ENABLED, captureToTexture); intent.putExtra(CallActivity.EXTRA_NOAUDIOPROCESSING_ENABLED, noAudioProcessing); intent.putExtra(CallActivity.EXTRA_AECDUMP_ENABLED, aecDump); intent.putExtra(CallActivity.EXTRA_OPENSLES_ENABLED, useOpenSLES); intent.putExtra(CallActivity.EXTRA_AUDIO_BITRATE, audioStartBitrate); intent.putExtra(CallActivity.EXTRA_AUDIOCODEC, audioCodec); intent.putExtra(CallActivity.EXTRA_DISPLAY_HUD, displayHud); intent.putExtra(CallActivity.EXTRA_TRACING, tracing); intent.putExtra(CallActivity.EXTRA_CMDLINE, commandLineRun); intent.putExtra(CallActivity.EXTRA_RUNTIME, runTimeMs); } roomListView = (ListView) findViewById(R.id.room_listview); roomListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); connectButton = (ImageButton) findViewById(R.id.connect_button); connectButton.setOnClickListener(connectListener); // If an implicit VIEW intent is launching the app, go directly to that URL. //final Intent intent = getIntent(); Uri wsurl = Uri.parse(Configs.ROOM_URL); //intent.getData(); Log.d(TAG, "connecting to:" + wsurl.toString()); if (wsurl == null) { logAndToast(getString(R.string.missing_wsurl)); Log.e(TAG, "Didn't get any URL in intent!"); setResult(RESULT_CANCELED); finish(); return; } if (from == null || from.length() == 0) { logAndToast(getString(R.string.missing_from)); Log.e(TAG, "Incorrect from in intent!"); setResult(RESULT_CANCELED); finish(); return; } peerConnectionParameters = new PeerConnectionClient.PeerConnectionParameters(videoCallEnabled, tracing, videoWidth, videoHeight, cameraFps, videoStartBitrate, videoCodec, hwCodec, captureToTexture, audioStartBitrate, audioCodec, noAudioProcessing, aecDump, useOpenSLES); roomConnectionParameters = new AppRTCClient.RoomConnectionParameters(wsurl.toString(), from, false); Log.i(TAG, "creating appRtcClient with roomUri:" + wsurl.toString() + " from:" + from); // Create connection client and connection parameters. appRtcClient = new WebSocketRTCClient(this, new LooperExecutor()); connectToWebsocket(); // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.ThreadViewFragment.java
/** * Set up the ListView, adapter, listener for pullRoRefresh and OnItemClick listener. *///from w ww .j a v a2s . c o m @Override public void onStart() { super.onStart(); threadView = (PullToRefreshListView) getView().findViewById(R.id.thread_view_list); adapter = new ThreadViewAdapter(getActivity(), thread, getFragmentManager(), threadIndex); threadView.setAdapter(adapter); adapter.notifyDataSetChanged(); threadView.setOnItemClickListener(commentButtonListener); threadView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { if (!connectHelper.isConnected()) { Toaster.toastShort("No network connection."); threadView.onRefreshComplete(); } else if (isFavCom == -1) { threadView.onRefreshComplete(); } else { reload(); } } }); // Toggle PullToRefresh programatically on start if (!refresh && isFavCom != -1 && connectHelper.isConnected()) { threadView.setRefreshing(); ThreadManager.startGetComments(this, threadIndex); refresh = true; } //threadView.setRefreshing(); Fragment fav = getFragmentManager().findFragmentByTag("favThrFragment"); if (fav != null) { container = R.id.container; } else { container = R.id.fragment_container; } updateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (isVisible() && connectHelper.getWasNotConnected() == true) { connectHelper.setWasNotConnected(false); UpdateDialogFragment fragment = new UpdateDialogFragment(); fragment.show(getFragmentManager(), "updateDialogFrag"); } } }; getActivity().getApplicationContext().registerReceiver(updateReceiver, new IntentFilter(ConnectivityBroadcastReceiver.UPDATE_FROM_SERVER_INTENT)); }
From source file:com.tml.sharethem.sender.SHAREthemActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sender); //init UI/*from w w w. j a v a 2 s. c om*/ m_sender_wifi_info = (TextView) findViewById(R.id.p2p_sender_wifi_hint); m_noReceiversText = (TextView) findViewById(R.id.p2p_no_receivers_text); m_showShareList = (TextView) findViewById(R.id.p2p_sender_items_label); m_showShareList.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showSharedFilesDialog(); } }); m_receivers_list_layout = (RelativeLayout) findViewById(R.id.p2p_receivers_list_layout); m_receiversList = (RecyclerView) findViewById(R.id.p2p_receivers_list); m_apControlSwitch = (SwitchCompat) findViewById(R.id.p2p_sender_ap_switch); m_toolbar = (Toolbar) findViewById(R.id.toolbar); m_toolbar.setTitle(getString(R.string.send_title)); setSupportActionBar(m_toolbar); getSupportActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); hotspotControl = HotspotControl.getInstance(getApplicationContext()); m_receiversList.setLayoutManager(new LinearLayoutManager(getApplicationContext())); m_receiversList .addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.list_divider))); //if file paths are found, save'em into preferences. OR find them in prefs if (null != getIntent() && getIntent().hasExtra(SHAREthemService.EXTRA_FILE_PATHS)) m_sharedFilePaths = getIntent().getStringArrayExtra(SHAREthemService.EXTRA_FILE_PATHS); SharedPreferences prefs = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE); if (null == m_sharedFilePaths) m_sharedFilePaths = Utils.toStringArray(prefs.getString(PREFERENCES_KEY_SHARED_FILE_PATHS, null)); else prefs.edit().putString(PREFERENCES_KEY_SHARED_FILE_PATHS, new JSONArray(Arrays.asList(m_sharedFilePaths)).toString()).apply(); m_receiversListAdapter = new ReceiversListingAdapter(new ArrayList<HotspotControl.WifiScanResult>(), m_sharedFilePaths); m_receiversList.setAdapter(m_receiversListAdapter); m_sender_ap_switch_listener = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (!isOreoOrAbove()) { //If target version is MM and beyond, you need to check System Write permissions to proceed. if (Build.VERSION.SDK_INT >= 23 && // if targetSdkVersion >= 23 // ShareActivity has to check for System Write permissions to proceed Utils.getTargetSDKVersion(getApplicationContext()) >= 23 && !Settings.System.canWrite(SHAREthemActivity.this)) { changeApControlCheckedStatus(false); showMessageDialogWithListner( getString(R.string.p2p_sender_system_settings_permission_prompt), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivityForResult(intent, REQUEST_WRITE_SETTINGS); } }, false, true); return; } else if (!getSharedPreferences(getPackageName(), Context.MODE_PRIVATE) .getBoolean(PREFERENCES_KEY_DATA_WARNING_SKIP, false) && Utils.isMobileDataEnabled(getApplicationContext())) { changeApControlCheckedStatus(false); showDataWarningDialog(); return; } } else if (!checkLocationPermission()) { changeApControlCheckedStatus(false); return; } enableAp(); } else { changeApControlCheckedStatus(true); showMessageDialogWithListner(getString(R.string.p2p_sender_close_warning), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d(TAG, "sending intent to service to stop p2p.."); resetSenderUi(true); } }, true, false); } } }; m_apControlSwitch.setOnCheckedChangeListener(m_sender_ap_switch_listener); m_p2pServerUpdatesListener = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (isFinishing() || null == intent) return; int intentType = intent.getIntExtra(SHAREthemService.ShareIntents.TYPE, 0); if (intentType == SHAREthemService.ShareIntents.Types.FILE_TRANSFER_STATUS) { String fileName = intent .getStringExtra(SHAREthemService.ShareIntents.SHARE_SERVER_UPDATE_FILE_NAME); updateReceiverListItem(intent.getStringExtra(SHAREthemService.ShareIntents.SHARE_CLIENT_IP), intent.getIntExtra(SHAREthemService.ShareIntents.SHARE_TRANSFER_PROGRESS, -1), intent.getStringExtra(SHAREthemService.ShareIntents.SHARE_SERVER_UPDATE_TEXT), fileName); } else if (intentType == SHAREthemService.ShareIntents.Types.AP_DISABLED_ACKNOWLEDGEMENT) { shouldAutoConnect = false; resetSenderUi(false); } } }; registerReceiver(m_p2pServerUpdatesListener, new IntentFilter(SHAREthemService.ShareIntents.SHARE_SERVER_UPDATES_INTENT_ACTION)); }
From source file:com.fysl.app.main.MainActivity.java
private void registerBroadcastReceiver() { broadcastManager = LocalBroadcastManager.getInstance(this); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Constant.ACTION_CONTACT_CHANAGED); intentFilter.addAction(Constant.ACTION_GROUP_CHANAGED); broadcastReceiver = new BroadcastReceiver() { @Override/*from w w w . ja v a 2s . com*/ public void onReceive(Context context, Intent intent) { updateUnreadLabel(); updateUnreadAddressLable(); if (currentTabIndex == 2) { // ?????? if (conversationListFragment != null) { conversationListFragment.refresh(); } } else if (currentTabIndex == 3) { if (contactListFragment != null) { contactListFragment.refresh(); } } String action = intent.getAction(); if (action.equals(Constant.ACTION_GROUP_CHANAGED)) { if (EaseCommonUtils.getTopActivity(MainActivity.this).equals(GroupsActivity.class.getName())) { GroupsActivity.instance.onResume(); } } } }; broadcastManager.registerReceiver(broadcastReceiver, intentFilter); }
From source file:com.avcall.app.ui.MainActivity.java
private void registerBroadcastReceiver() { broadcastManager = LocalBroadcastManager.getInstance(this); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Constant.ACTION_CONTACT_CHANAGED); intentFilter.addAction(Constant.ACTION_GROUP_CHANAGED); intentFilter.addAction(RedPacketConstant.REFRESH_GROUP_RED_PACKET_ACTION); broadcastReceiver = new BroadcastReceiver() { @Override//ww w. ja v a 2s . c om public void onReceive(Context context, Intent intent) { updateUnreadLabel(); updateUnreadAddressLable(); if (currentTabIndex == 0) { // refresh conversation list if (conversationListFragment != null) { conversationListFragment.refresh(); } } else if (currentTabIndex == 1) { if (contactListFragment != null) { contactListFragment.refresh(); } } String action = intent.getAction(); if (action.equals(Constant.ACTION_GROUP_CHANAGED)) { if (EaseCommonUtils.getTopActivity(MainActivity.this).equals(GroupsActivity.class.getName())) { GroupsActivity.instance.onResume(); } } //red packet code : ??? if (action.equals(RedPacketConstant.REFRESH_GROUP_RED_PACKET_ACTION)) { if (conversationListFragment != null) { conversationListFragment.refresh(); } } //end of red packet code } }; broadcastManager.registerReceiver(broadcastReceiver, intentFilter); }
From source file:cn.xcom.helper.chat.ui.MainActivity.java
private void registerBroadcastReceiver() { broadcastManager = LocalBroadcastManager.getInstance(this); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Constant.ACTION_CONTACT_CHANAGED); intentFilter.addAction(Constant.ACTION_GROUP_CHANAGED); intentFilter.addAction(RedPacketConstant.REFRESH_GROUP_RED_PACKET_ACTION); broadcastReceiver = new BroadcastReceiver() { @Override/*from ww w .j a v a2 s.c o m*/ public void onReceive(Context context, Intent intent) { updateUnreadLabel(); updateUnreadAddressLable(); if (currentTabIndex == 0) { // refresh conversation list if (conversationListFragment != null) { conversationListFragment.refresh(); } } else if (currentTabIndex == 1) { if (contactListFragment != null) { contactListFragment.refresh(); } } String action = intent.getAction(); if (action.equals(Constant.ACTION_GROUP_CHANAGED)) { if (EaseCommonUtils.getTopActivity(MainActivity.this).equals(GroupsActivity.class.getName())) { GroupsActivity.instance.onResume(); } } if (action.equals(RedPacketConstant.REFRESH_GROUP_RED_PACKET_ACTION)) { if (conversationListFragment != null) { conversationListFragment.refresh(); } } } }; broadcastManager.registerReceiver(broadcastReceiver, intentFilter); }