List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:com.murrayc.galaxyzoo.app.ClassifyActivity.java
@Override public void listenForNetworkReconnection() { if (mReceiverNetworkReconnection != null) { Log.error("ClassifyActivity.listenForNetworkReconnection(): Already listening."); return;/* w w w .j a v a2 s. c om*/ } mReceiverNetworkReconnection = new BroadcastReceiver() { @Override public void onReceive(final Context context, final Intent intent) { final Utils.NetworkConnected networkConnected = Utils.getNetworkIsConnected(context, Utils.getUseWifiOnlyFromSharedPrefs(ClassifyActivity.this)); if ((networkConnected != null) && (networkConnected.connected)) { //Try using the network again: ClassifyActivity.this.stopListeningForNetworkReconnection(); ClassifyActivity.this.startNextClassification(); } } }; final IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(mReceiverNetworkReconnection, filter); }
From source file:com.supremainc.biostar2.user.MyProfileFragment.java
@Override protected void registerBroadcast() { if (mReceiver == null) { mReceiver = new BroadcastReceiver() { @Override//from www . ja v a 2s . c o m public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (mIsDestroy) { return; } if (action.equals(Setting.BROADCAST_UPDATE_FINGER)) { ArrayList<ListFingerprintTemplate> fingerTemplate = getExtraData( Setting.BROADCAST_UPDATE_FINGER, intent); if (fingerTemplate == null) { return; } if (mUserInfo != null) { mUserInfo.fingerprint_templates = fingerTemplate; mUserInfo.fingerprint_count = fingerTemplate.size(); } setFingerCount(); return; } if (action.equals(Setting.BROADCAST_UPDATE_CARD)) { ArrayList<ListCard> Cards = getExtraData(Setting.BROADCAST_UPDATE_CARD, intent); if (Cards == null) { return; } if (mUserInfo != null) { mUserInfo.cards = Cards; mUserInfo.card_count = Cards.size(); } setCardCount(); return; } if (action.equals(Setting.BROADCAST_UPDATE_USER_ACCESS_GROUP)) { ArrayList<ListAccessGroup> accessGroups = getExtraData( Setting.BROADCAST_UPDATE_USER_ACCESS_GROUP, intent); if (accessGroups == null) { return; } if (mUserInfo != null) { mUserInfo.access_groups = accessGroups; } setAccessGroupCount(); return; } if (action.equals(Setting.BROADCAST_PREFRENCE_REFRESH)) { if (mLayout == null || mContext == null) { return; } mLayout.setDateStart(mUserInfo.getTimeFormmat(mTimeConvertProvider, User.UserTimeType.start_datetime, TimeConvertProvider.DATE_TYPE.FORMAT_DATE)); mLayout.setDateEnd(mUserInfo.getTimeFormmat(mTimeConvertProvider, User.UserTimeType.expiry_datetime, TimeConvertProvider.DATE_TYPE.FORMAT_DATE)); return; } if (action.equals(Setting.BROADCAST_UPDATE_PERMISSION)) { ArrayList<CloudRole> roles = getExtraData(Setting.BROADCAST_UPDATE_PERMISSION, intent); if (roles == null) { return; } if (mUserInfo != null) { mUserInfo.roles = roles; } setPermission(); return; } } }; IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Setting.BROADCAST_UPDATE_FINGER); intentFilter.addAction(Setting.BROADCAST_UPDATE_CARD); intentFilter.addAction(Setting.BROADCAST_UPDATE_USER_ACCESS_GROUP); intentFilter.addAction(Setting.BROADCAST_PREFRENCE_REFRESH); intentFilter.addAction(Setting.BROADCAST_UPDATE_PERMISSION); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, intentFilter); } }
From source file:com.koma.music.service.MusicService.java
/** * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. The * intent will call closeExternalStorageFiles() if the external media is * going to be ejected, so applications can clean up any files they have * open.//from ww w . j av a2 s.com */ public void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { /** * {@inheritDoc} */ @Override public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_EJECT)) { saveQueue(true); mQueueIsSaveable = false; closeExternalStorageFiles(intent.getData().getPath()); } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { mMediaMountedCount++; mCardId = getCardId(); reloadQueue(); mQueueIsSaveable = true; notifyChange(MusicServiceConstants.QUEUE_CHANGED); notifyChange(META_CHANGED); } } }; final IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_MEDIA_EJECT); filter.addAction(Intent.ACTION_MEDIA_MOUNTED); filter.addDataScheme("file"); registerReceiver(mUnmountReceiver, filter); } }
From source file:com.nexmo.sdk.verify.client.VerifyClient.java
/** * Handle the managedUI notifications broadcast receiver, update {@link VerifyClient} on progress. *///from w ww.j av a2 s. c om private void setManagedUIBroadcastReceiver() { this.managedVerifyUIReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (extras != null) { ManagedVerifyResponse response = extras .getParcelable(ManagedVerifyResponse.class.getSimpleName()); if (response != null && !response.isIoExceptionOccured()) { updateVerifyRequest(response.getPhone()); if (response.getUserStatus() == UserStatus.USER_PENDING) { handleUserStateChanged(UserStatus.USER_PENDING); commandsHandler.postDelayed(commandsRunnable, 30000); } else if (response.getUserStatus() == UserStatus.USER_VERIFIED) handleUserStateChanged(UserStatus.USER_VERIFIED); else if (response.getUserStatus() == UserStatus.USER_FAILED) handleUserStateChanged(UserStatus.USER_FAILED); else notifyErrorListeners(response.getVerifyError()); } else handleNetworkException(new IOException("Network exception")); } } }; LocalBroadcastManager.getInstance(this.nexmoClient.getContext()).registerReceiver( this.managedVerifyUIReceiver, new IntentFilter(VerifyPhoneNumberActivity.ACTION_BROADCAST_MANAGED_EVENT)); }
From source file:cn.ucai.superwechat.ui.MainActivity.java
/** * debug purpose only, you can ignore this *///from w w w .j a va 2 s . c o m private void registerInternalDebugReceiver() { internalDebugReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { SuperWeChatDemoHelper.getInstance().logout(false, new EMCallBack() { @Override public void onSuccess() { runOnUiThread(new Runnable() { public void run() { finish(); startActivity(new Intent(MainActivity.this, LoginActivity.class)); } }); } @Override public void onProgress(int progress, String status) { } @Override public void onError(int code, String message) { } }); } }; IntentFilter filter = new IntentFilter(getPackageName() + ".em_internal_debug"); registerReceiver(internalDebugReceiver, filter); }
From source file:com.zertinteractive.wallpaper.MainActivity.java
public void initDownloadComponents() { BroadcastReceiver receiver = new BroadcastReceiver() { @Override//from ww w.ja v a2s . co m public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { // } } }; registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); unregisterReceiver(receiver); }
From source file:com.tct.mail.browse.ConversationItemView.java
private static synchronized void getItemViewResources(Context context) { if (sConfigurationChangedReceiver == null) { sConfigurationChangedReceiver = new BroadcastReceiver() { @Override//from w w w .j av a 2s. c om public void onReceive(Context context, Intent intent) { STAR_OFF = null; //[BUGFIX]-Mod-BEGIN by TCTNB.caixia.chen,01/07/2015,PR 893304 getItemViewResources(context.getApplicationContext()); //[BUGFIX]-Mod-END by TCTNB.caixia.chen } }; context.registerReceiver(sConfigurationChangedReceiver, new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); } if (STAR_OFF == null) { final Resources res = context.getResources(); // Initialize static bitmaps. //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 MOD-S // star off will not show in list item. //STAR_OFF = BitmapFactory.decodeResource(res, R.drawable.ic_star_outline_20dp); STAR_OFF = BitmapFactory.decodeResource(res, R.drawable.ic_importance_normal); //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 MOD-S STAR_ON = BitmapFactory.decodeResource(res, R.drawable.ic_star_20dp); ATTACHMENT = BitmapFactory.decodeResource(res, R.drawable.ic_attach_file_20dp); ONLY_TO_ME = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_double); TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_single); IMPORTANT_ONLY_TO_ME = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_double_important_unread); IMPORTANT_TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_single_important_unread); IMPORTANT = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_none_important_unread); STATE_REPLIED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_reply_holo_light); STATE_FORWARDED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_forward_holo_light); STATE_REPLIED_AND_FORWARDED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_reply_forward_holo_light); STATE_CALENDAR_INVITE = BitmapFactory.decodeResource(res, R.drawable.ic_badge_invite_holo_light); VISIBLE_CONVERSATION_HIGHLIGHT = res.getDrawable(R.drawable.visible_conversation_highlight); RIGHT_EDGE_TABLET = res.getDrawable(R.drawable.list_edge_tablet); //[FEATURE]-Add-BEGIN by TSCD.chao zhang,04/17/2014,FR 631895(porting from FR514398) sHighPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_high_priority); sLowPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_low_priority); sNormalPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_importance_normal); //[FEATURE]-Add-END by TSCD.chao zhang // Initialize colors. sActivatedTextSpan = CharacterStyle .wrap(new ForegroundColorSpan(res.getColor(R.color.senders_text_color))); sSendersTextColor = res.getColor(R.color.senders_text_color); sSubjectTextUnreadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceUnreadStyle); sSubjectTextReadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceReadStyle); sBadgeTextSpan = new TextAppearanceSpan(context, R.style.BadgeTextStyle); sBadgeBackgroundSpan = new BackgroundColorSpan(res.getColor(R.color.badge_background_color)); sDateTextColorRead = res.getColor(R.color.date_text_color_read); sDateTextColorUnread = res.getColor(R.color.date_text_color_unread); sStarTouchSlop = res.getDimensionPixelSize(R.dimen.star_touch_slop); sSenderImageTouchSlop = res.getDimensionPixelSize(R.dimen.sender_image_touch_slop); sShrinkAnimationDuration = res.getInteger(R.integer.shrink_animation_duration); sSlideAnimationDuration = res.getInteger(R.integer.slide_animation_duration); // Initialize static color. sSendersSplitToken = res.getString(R.string.senders_split_token); sElidedPaddingToken = res.getString(R.string.elided_padding_token); sScrollSlop = res.getInteger(R.integer.swipeScrollSlop); sFoldersStartPadding = res.getDimensionPixelOffset(R.dimen.folders_start_padding); sFoldersInnerPadding = res.getDimensionPixelOffset(R.dimen.folder_cell_content_padding); sFoldersMaxCount = res.getInteger(R.integer.conversation_list_max_folder_count); sFoldersOverflowGradientPadding = res.getDimensionPixelOffset(R.dimen.folders_gradient_padding); sCabAnimationDuration = res.getInteger(R.integer.conv_item_view_cab_anim_duration); sBadgePaddingExtraWidth = res.getDimensionPixelSize(R.dimen.badge_padding_extra_width); sBadgeRoundedCornerRadius = res.getDimensionPixelSize(R.dimen.badge_rounded_corner_radius); sFolderRoundedCornerRadius = res.getDimensionPixelOffset(R.dimen.folder_rounded_corner_radius); sDividerColor = res.getColor(R.color.conversation_list_divider_color); sDividerInset = res.getDimensionPixelSize(R.dimen.conv_list_divider_inset); sDividerHeight = res.getDimensionPixelSize(R.dimen.divider_height); } }
From source file:com.scooter1556.sms.lib.android.service.AudioPlayerService.java
private void registerAudioManagerReceiver() { IntentFilter filter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY); audioManagerReceiver = new BroadcastReceiver() { @Override//w w w .j a va 2s . co m public void onReceive(Context context, Intent intent) { if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) { // Pause playback pause(); } } }; registerReceiver(audioManagerReceiver, filter); }
From source file:se.lu.nateko.edca.svc.GeoHelper.java
/** * Start to listen for changes in the storage state, * and report any changes to handleStorageChange. */// w ww . ja v a 2 s . co m private void startWatchingExternalStorage() { Log.d(TAG, "startWatchingExternalStorage() called."); mExternalStorageReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.i("TAG", "Storage state changed: " + intent.getData()); updateExternalStorageState(); handleStorageChange(); } }; IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_MEDIA_MOUNTED); filter.addAction(Intent.ACTION_MEDIA_REMOVED); mService.registerReceiver(mExternalStorageReceiver, filter); updateExternalStorageState(); }
From source file:com.av.remusic.service.MediaService.java
public void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override/*w w w . j av a2 s .com*/ public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_EJECT)) { saveQueue(true); mQueueIsSaveable = false; closeExternalStorageFiles(intent.getData().getPath()); } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { mMediaMountedCount++; mCardId = getCardId(); reloadQueueAfterPermissionCheck(); mQueueIsSaveable = true; notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); } } }; final IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_MEDIA_EJECT); filter.addAction(Intent.ACTION_MEDIA_MOUNTED); filter.addDataScheme("file"); registerReceiver(mUnmountReceiver, filter); } }