List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:com.eusecom.attendance.StorageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_storage); // Initialize Firebase Auth mAuth = FirebaseAuth.getInstance();/*from w w w . ja v a 2 s.c o m*/ // Initialize Firebase Storage Ref // [START get_storage_ref] mStorageRef = FirebaseStorage.getInstance().getReference(); // [END get_storage_ref] // Click listeners findViewById(R.id.button_camera).setOnClickListener(this); findViewById(R.id.button_sign_in).setOnClickListener(this); findViewById(R.id.button_download).setOnClickListener(this); // Restore instance state if (savedInstanceState != null) { mFileUri = savedInstanceState.getParcelable(KEY_FILE_URI); mDownloadUrl = savedInstanceState.getParcelable(KEY_DOWNLOAD_URL); } // Download receiver mDownloadReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "downloadReceiver:onReceive:" + intent); hideProgressDialog(); if (com.eusecom.attendance.MyDownloadService.ACTION_COMPLETED.equals(intent.getAction())) { String path = intent .getStringExtra(com.eusecom.attendance.MyDownloadService.EXTRA_DOWNLOAD_PATH); long numBytes = intent .getLongExtra(com.eusecom.attendance.MyDownloadService.EXTRA_BYTES_DOWNLOADED, 0); // Alert success showMessageDialog("Success", String.format(Locale.getDefault(), "%d bytes downloaded from %s", numBytes, path)); } if (com.eusecom.attendance.MyDownloadService.ACTION_ERROR.equals(intent.getAction())) { String path = intent .getStringExtra(com.eusecom.attendance.MyDownloadService.EXTRA_DOWNLOAD_PATH); // Alert failure showMessageDialog("Error", String.format(Locale.getDefault(), "Failed to download from %s", path)); } } }; }
From source file:is.hello.buruberi.bluetooth.stacks.android.NativeBluetoothStack.java
@RequiresPermission(Manifest.permission.BLUETOOTH) public NativeBluetoothStack(@NonNull Context applicationContext, @NonNull ErrorListener errorListener, @NonNull LoggerFacade logger) {//from w w w. ja v a2 s . co m this.applicationContext = applicationContext; this.errorListener = errorListener; this.logger = logger; this.bluetoothManager = (BluetoothManager) applicationContext.getSystemService(Context.BLUETOOTH_SERVICE); this.adapter = bluetoothManager.getAdapter(); if (adapter != null) { final BroadcastReceiver powerStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); if (newState == BluetoothAdapter.STATE_ON) { enabled.onNext(true); } else if (newState == BluetoothAdapter.STATE_OFF || newState == BluetoothAdapter.ERROR) { enabled.onNext(false); } } }; applicationContext.registerReceiver(powerStateReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)); enabled.onNext(adapter.isEnabled()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { final BroadcastReceiver pairingReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); final Intent broadcast = new Intent(ACTION_PAIRING_REQUEST); broadcast.putExtra(GattPeripheral.EXTRA_NAME, device.getName()); broadcast.putExtra(GattPeripheral.EXTRA_ADDRESS, device.getAddress()); LocalBroadcastManager.getInstance(context).sendBroadcast(broadcast); } }; applicationContext.registerReceiver(pairingReceiver, new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST)); } } else { logger.warn(LOG_TAG, "Host device has no bluetooth hardware!"); enabled.onNext(false); } }
From source file:eu.power_switch.gui.fragment.configure_timer.ConfigureTimerDialogPage3ActionFragment.java
@Nullable @Override/*from ww w .j a va2s .c om*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.dialog_fragment_configure_timer_page_3, container, false); // BroadcastReceiver to get notifications from background service if room data has changed broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { sendTimerActionChangedBroadcast(getContext(), currentActions); } }; final Fragment fragment = this; FloatingActionButton addTimerActionFAB = (FloatingActionButton) rootView .findViewById(R.id.add_timer_action); addTimerActionFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(), ContextCompat.getColor(getActivity(), android.R.color.white))); addTimerActionFAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AddTimerActionDialog addTimerActionDialog = new AddTimerActionDialog(); addTimerActionDialog.setTargetFragment(fragment, 0); addTimerActionDialog.show(getActivity().getSupportFragmentManager(), null); } }); currentActions = new ArrayList<>(); actionRecyclerViewAdapter = new ActionRecyclerViewAdapter(getActivity(), currentActions); actionRecyclerViewAdapter.setOnDeleteClickListener(new ActionRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(View itemView, int position) { currentActions.remove(position); actionRecyclerViewAdapter.notifyDataSetChanged(); sendTimerActionChangedBroadcast(getContext(), currentActions); } }); RecyclerView recyclerViewTimerActions = (RecyclerView) rootView .findViewById(R.id.recyclerview_list_of_actions); recyclerViewTimerActions.setAdapter(actionRecyclerViewAdapter); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL); recyclerViewTimerActions.setLayoutManager(layoutManager); Bundle args = getArguments(); if (args != null && args.containsKey(ConfigureTimerDialog.TIMER_ID_KEY)) { long timerId = args.getLong(ConfigureTimerDialog.TIMER_ID_KEY); initializeTimerData(timerId); } sendTimerActionChangedBroadcast(getContext(), currentActions); return rootView; }
From source file:com.ibm.cloud.appid.android.internal.authorizationmanager.ChromeTabActivity.java
@Override public void onCreate(Bundle savedInstanceBundle) { logger.debug("onCreate"); super.onCreate(savedInstanceBundle); postAuthorizationIntent = getApplicationContext().getPackageName() + postAuthorizationIntent; Intent intent = getIntent();/*from www .j ava2 s.c om*/ if (!postAuthorizationIntent.equals(intent.getAction())) { String serverUrl = getIntent().getStringExtra(AuthorizationUIManager.EXTRA_URL); this.redirectUrl = getIntent().getStringExtra(AuthorizationUIManager.EXTRA_REDIRECT_URL); String authFlowContextGuid = getIntent() .getStringExtra(AuthorizationUIManager.EXTRA_AUTH_FLOW_CONTEXT_GUID); AuthorizationFlowContext ctx = AuthorizationFlowContextStore.remove(authFlowContextGuid); this.oAuthManager = ctx.getOAuthManager(); this.authorizationListener = ctx.getAuthorizationListener(); logger.debug("serverUrl: " + serverUrl); logger.debug("redirectUrl: " + redirectUrl); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.enableUrlBarHiding(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.intent .setPackage(AuthorizationUIManager.getPackageNameToUse(this.getApplicationContext())); customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { onBroadcastReceived(intent); } }; IntentFilter intentFilter = new IntentFilter(INTENT_GOT_HTTP_REDIRECT); LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, intentFilter); //This will launch the chrome tab Uri uri = Uri.parse(serverUrl); logger.debug("launching custom tab with url: " + uri.toString()); customTabsIntent.launchUrl(this, uri); } else { //if we launch after authorization completed finish(); } }
From source file:com.example.evan.comp296.profile.MainActivity_Profile.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_profile); // Initialize Firebase Auth mAuth = FirebaseAuth.getInstance();/*from w ww.java 2 s .com*/ // Click listeners findViewById(R.id.button_camera).setOnClickListener(this); findViewById(R.id.button_sign_in).setOnClickListener(this); findViewById(R.id.button_download).setOnClickListener(this); findViewById(R.id.button_cancel).setOnClickListener(this); // Restore instance state if (savedInstanceState != null) { mFileUri = savedInstanceState.getParcelable(KEY_FILE_URI); mDownloadUrl = savedInstanceState.getParcelable(KEY_DOWNLOAD_URL); } onNewIntent(getIntent()); // Local broadcast receiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "onReceive:" + intent); hideProgressDialog(); switch (intent.getAction()) { case MyDownloadService.DOWNLOAD_COMPLETED: // Get number of bytes downloaded long numBytes = intent.getLongExtra(MyDownloadService.EXTRA_BYTES_DOWNLOADED, 0); // Alert success showMessageDialog(getString(R.string.success), String.format(Locale.getDefault(), "%d bytes downloaded from %s", numBytes, intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH))); break; case MyDownloadService.DOWNLOAD_ERROR: // Alert failure showMessageDialog("Error", String.format(Locale.getDefault(), "Failed to download from %s", intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH))); break; case MyUploadService.UPLOAD_COMPLETED: case MyUploadService.UPLOAD_ERROR: try { onUploadResultIntent(intent); } catch (IOException e) { e.printStackTrace(); } break; } } }; }
From source file:de.markusressel.android.pageindicatorview.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pageIndicatorView = (PageIndicatorView) findViewById(R.id.pageIndicator); pageIndicatorView.setOnIndicatorClickedListener(new OnIndicatorClickedListener() { @Override//from www.j av a 2 s . c o m public void onIndicatorClicked(PageIndicatorView pageIndicatorView, int index) { pageIndicatorView.setCurrentPage(index, true); tabViewPager.setCurrentItem(index); } }); // Create the adapter that will return a fragment // for each of the two primary sections of the app. customTabAdapter = new CustomTabAdapter(getFragmentManager(), this); // Set up the tabViewPager, attaching the adapter and setting up a listener // for when the user swipes between sections. tabViewPager = (ViewPager) findViewById(R.id.viewPager); tabViewPager.setAdapter(customTabAdapter); tabViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { pageIndicatorView.setCurrentPage(position, true); } @Override public void onPageScrollStateChanged(int state) { } }); initFromPreferenceValues(); // this receiver will update the view if a preference has changed broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (SettingsPage.INTENT_ACTION_PREFERENCE_CHANGED.equals(intent.getAction())) { String key = intent.getStringExtra(SettingsPage.KEY_PREFERENCE_KEY); if (getString(R.string.key_activeIndicatorFillColor).equals(key)) { @ColorInt int activeIndicatorColorFill = PreferencesHelper.getColor(getApplicationContext(), R.string.key_activeIndicatorFillColor, getResources().getColor(R.color.default_value_activeIndicatorFillColor)); pageIndicatorView.setActiveIndicatorFillColor(activeIndicatorColorFill); } else if (getString(R.string.key_activeIndicatorStrokeColor).equals(key)) { @ColorInt int activeIndicatorColorStroke = PreferencesHelper.getColor(getApplicationContext(), R.string.key_activeIndicatorStrokeColor, getResources().getColor(R.color.default_value_activeIndicatorStrokeColor)); pageIndicatorView.setActiveIndicatorStrokeColor(activeIndicatorColorStroke); } else if (getString(R.string.key_activeIndicatorStrokeWidth).equals(key)) { float activeIndicatorStrokeWidth = PreferencesHelper.getDimen(getApplicationContext(), R.string.key_activeIndicatorStrokeWidth, R.dimen.default_value_activeIndicatorStrokeWidth); pageIndicatorView.setActiveIndicatorStrokeWidth( Math.round(pxFromDp(getApplicationContext(), activeIndicatorStrokeWidth))); } else if (getString(R.string.key_activeIndicatorFillSize).equals(key)) { float activeIndicatorSize = PreferencesHelper.getDimen(getApplicationContext(), R.string.key_activeIndicatorFillSize, R.dimen.default_value_activeIndicatorFillSize); pageIndicatorView.setActiveIndicatorSize( Math.round(pxFromDp(getApplicationContext(), activeIndicatorSize))); } else if (getString(R.string.key_inactiveIndicatorFillColor).equals(key)) { @ColorInt int inactiveIndicatorColorFill = PreferencesHelper.getColor(getApplicationContext(), R.string.key_inactiveIndicatorFillColor, getResources().getColor(R.color.default_value_inactiveIndicatorFillColor)); pageIndicatorView.setInactiveIndicatorFillColor(inactiveIndicatorColorFill); } else if (getString(R.string.key_inactiveIndicatorStrokeColor).equals(key)) { @ColorInt int inactiveIndicatorColorStroke = PreferencesHelper.getColor(getApplicationContext(), R.string.key_inactiveIndicatorStrokeColor, getResources().getColor(R.color.default_value_inactiveIndicatorStrokeColor)); pageIndicatorView.setInactiveIndicatorStrokeColor(inactiveIndicatorColorStroke); } else if (getString(R.string.key_inactiveIndicatorStrokeWidth).equals(key)) { float inactiveIndicatorStrokeWidth = PreferencesHelper.getDimen(getApplicationContext(), R.string.key_inactiveIndicatorStrokeWidth, R.dimen.default_value_inactiveIndicatorStrokeWidth); pageIndicatorView.setInactiveIndicatorStrokeWidth( Math.round(pxFromDp(getApplicationContext(), inactiveIndicatorStrokeWidth))); } else if (getString(R.string.key_inactiveIndicatorFillSize).equals(key)) { float inactiveIndicatorSize = PreferencesHelper.getDimen(getApplicationContext(), R.string.key_inactiveIndicatorFillSize, R.dimen.default_value_inactiveIndicatorFillSize); pageIndicatorView.setInactiveIndicatorSize( Math.round(pxFromDp(getApplicationContext(), inactiveIndicatorSize))); } else if (getString(R.string.key_indicatorGap).equals(key)) { float indicatorGap = PreferencesHelper.getDimen(getApplicationContext(), R.string.key_indicatorGap, R.dimen.default_value_indicatorGap); pageIndicatorView .setIndicatorGap(Math.round(pxFromDp(getApplicationContext(), indicatorGap))); } else if (getString(R.string.key_initialPageIndex).equals(key)) { int initialPageIndex = PreferencesHelper.getInteger(getApplicationContext(), R.string.key_initialPageIndex, R.integer.default_value_initialPageIndex); // TODO } else if (getString(R.string.key_pageCount).equals(key)) { int pageCount = PreferencesHelper.getInteger(getApplicationContext(), R.string.key_pageCount, R.integer.default_value_pageCount); customTabAdapter.setCount(pageCount); pageIndicatorView.setPageCount(pageCount); } } } }; }
From source file:com.groksolutions.grok.mobile.instance.InstanceListFragment.java
/** * InstanceListFragment constructor// www.j a v a 2 s .c o m */ public InstanceListFragment() { // Listen for new metric data _metricDataChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateMetricData(); } }; // Listens for new metrics _metricChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateInstanceList(); } }; // Listen for annotations _annotationChangedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateMetricData(); } }; }
From source file:com.demo.firebase.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize Firebase Auth mAuth = FirebaseAuth.getInstance();/* w w w .ja va2 s . co m*/ // Click listeners findViewById(R.id.button_camera).setOnClickListener(this); findViewById(R.id.button_sign_in).setOnClickListener(this); findViewById(R.id.button_download).setOnClickListener(this); // Restore instance state if (savedInstanceState != null) { mFileUri = savedInstanceState.getParcelable(KEY_FILE_URI); mDownloadUrl = savedInstanceState.getParcelable(KEY_DOWNLOAD_URL); } onNewIntent(getIntent()); // Local broadcast receiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "onReceive:" + intent); hideProgressDialog(); switch (intent.getAction()) { case MyDownloadService.DOWNLOAD_COMPLETED: // Get number of bytes downloaded long numBytes = intent.getLongExtra(MyDownloadService.EXTRA_BYTES_DOWNLOADED, 0); // Alert success showMessageDialog(getString(R.string.success), String.format(Locale.getDefault(), "%d bytes downloaded from %s", numBytes, intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH))); break; case MyDownloadService.DOWNLOAD_ERROR: // Alert failure showMessageDialog("Error", String.format(Locale.getDefault(), "Failed to download from %s", intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH))); break; case MyUploadService.UPLOAD_COMPLETED: case MyUploadService.UPLOAD_ERROR: onUploadResultIntent(intent); break; } } }; }
From source file:cn.bingoogolapple.scaffolding.util.AppManager.java
private AppManager() { // ?// www. ja v a 2 s .c o m CrashHandler.getInstance().init(); sApp.registerReceiver(new BroadcastReceiver() { private boolean mIsFirstReceiveBroadcast = true; @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { if (!mIsFirstReceiveBroadcast) { try { if (NetUtil.isNetworkAvailable()) { RxBus.send(new RxEvent.NetworkConnectedEvent()); } else { RxBus.send(new RxEvent.NetworkDisconnectedEvent()); } } catch (Exception e) { } } else { mIsFirstReceiveBroadcast = false; } } } }, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); }
From source file:eu.power_switch.gui.fragment.configure_scene.ConfigureSceneDialogTabbedPage2SetupFragment.java
@Nullable @Override//w w w. j a va 2 s . c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.dialog_fragment_configure_scene_page_2, container, false); // BroadcastReceiver to get notifications from background service if room data has changed broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { currentName = intent.getStringExtra("name"); rooms.clear(); rooms.addAll((ArrayList<Room>) intent.getSerializableExtra("selectedReceivers")); updateSceneItemList(); notifyConfigurationChanged(); } }; rooms = new ArrayList<>(); customRecyclerViewAdapter = new CustomRecyclerViewAdapter(getActivity(), rooms); recyclerViewSelectedReceivers = (RecyclerView) rootView.findViewById(R.id.recyclerview_list_of_receivers); recyclerViewSelectedReceivers.setAdapter(customRecyclerViewAdapter); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager( getResources().getInteger(R.integer.scene_grid_span_count), StaggeredGridLayoutManager.VERTICAL); recyclerViewSelectedReceivers.setLayoutManager(layoutManager); Bundle args = getArguments(); if (args != null && args.containsKey(ConfigureSceneDialog.SCENE_ID_KEY)) { currentId = args.getLong(ConfigureSceneDialog.SCENE_ID_KEY); initializeSceneData(currentId); } checkSetupValidity(); return rootView; }