List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:com.golden.android.eyecare.ForegroundService.java
@Override public void onCreate() { super.onCreate(); context = getApplicationContext();/*from ww w . j av a 2 s .co m*/ global = (Global) getApplicationContext(); final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); final BroadcastReceiver screenoffReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { Log.v("screenoffReceiver", "SCREEN OFF"); onDestroy(); stopForeground(Boolean.TRUE); } return; } }; registerReceiver(screenoffReceiver, filter); }
From source file:com.weebly.opus1269.copyeverywhere.ui.devices.DevicesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_devices); final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.deviceList); if (recyclerView != null) { mAdapter = new DevicesAdapter(); recyclerView.setAdapter(mAdapter); recyclerView.setLayoutManager(new LinearLayoutManager(this)); }/*from w ww. ja v a 2 s.c o m*/ final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); if (fab != null) { fab.hide(); } final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } // handler for received Intents for the "devices" event mDevicesReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { notifyAdapter(intent); } private void notifyAdapter(Intent intent) { final Bundle bundle = intent.getBundleExtra(Devices.BUNDLE); final String action = bundle.getString(Devices.ACTION); final int pos = bundle.getInt(Devices.POS); if (action == null) { return; } AppUtils.log(TAG, "Devices change: " + action + " pos: " + pos); switch (action) { case Devices.ACTION_ADD: mAdapter.notifyItemInserted(pos); break; case Devices.ACTION_REMOVE: mAdapter.notifyItemRemoved(pos); break; case Devices.ACTION_CLEAR: mAdapter.notifyDataSetChanged(); break; default: break; } } }; }
From source file:eu.power_switch.gui.fragment.configure_call.ConfigureCallDialogPage1ContactsFragment.java
@Nullable @Override//from ww w .j av a2s. co m public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.dialog_fragment_configure_call_page_1, container, false); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (LocalBroadcastConstants.INTENT_CALL_PHONE_NUMBER_ADDED.equals(intent.getAction())) { ArrayList<String> newPhoneNumbers = intent .getStringArrayListExtra(AddPhoneNumberDialog.KEY_PHONE_NUMBER); for (String number : newPhoneNumbers) { if (!phoneNumbers.contains(number)) { phoneNumbers.add(number); } } phoneNumberRecyclerViewAdapter.notifyDataSetChanged(); } } }; recyclerViewContacts = (RecyclerView) rootView.findViewById(R.id.recyclerView_contacts); phoneNumberRecyclerViewAdapter = new PhoneNumberRecyclerViewAdapter(getActivity(), phoneNumbers); recyclerViewContacts.setAdapter(phoneNumberRecyclerViewAdapter); phoneNumberRecyclerViewAdapter .setOnDeleteClickListener(new PhoneNumberRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(View itemView, final int position) { new AlertDialog.Builder(getContext()).setTitle(R.string.delete) .setMessage(R.string.are_you_sure) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { phoneNumbers.remove(position); phoneNumberRecyclerViewAdapter.notifyDataSetChanged(); notifyConfigurationChanged(); } catch (Exception e) { StatusMessageHandler.showErrorMessage(getActivity(), e); } } }).setNeutralButton(android.R.string.cancel, null).show(); } }); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL); recyclerViewContacts.setLayoutManager(layoutManager); final FloatingActionButton addContactFAB = (FloatingActionButton) rootView .findViewById(R.id.add_contact_fab); addContactFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(), ContextCompat.getColor(getActivity(), android.R.color.white))); final Fragment fragment = this; addContactFAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AddPhoneNumberDialog addPhoneNumberDialog = new AddPhoneNumberDialog(); addPhoneNumberDialog.setTargetFragment(fragment, 0); addPhoneNumberDialog.show(getFragmentManager(), null); } }); Bundle args = getArguments(); if (args != null && args.containsKey(ConfigureCallEventDialog.CALL_EVENT_ID_KEY)) { callEventId = args.getLong(ConfigureCallEventDialog.CALL_EVENT_ID_KEY); initializeCallData(callEventId); } return rootView; }
From source file:com.artur.softwareproject.BluetoothConnectionListAdapter.java
BluetoothConnectionListAdapter(Activity context, ArrayList<String> bluetoothAddress, ArrayList<String> bluetoothName, ArrayList<BluetoothDevice> bDevices) { super(context, R.layout.activity_bluetooth_connection, bluetoothAddress); this.bluetoothAddress = bluetoothAddress; this.bluetoothName = bluetoothName; this.bDevices = bDevices; this.contextActivity = context; this.intent = new Intent(); connected = 0;//w ww . ja v a2 s .c o m timeout = false; bluetoothServiceIntent = new Intent(context, BluetoothService.class); BroadcastReceiver connectedReceive = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { connected = (int) intent.getExtras().get("connected"); } }; LocalBroadcastManager.getInstance(context).registerReceiver(connectedReceive, new IntentFilter("connectedFilter")); }
From source file:com.example.xyzreader.ui.articlelist.ArticleListFragment.java
@Override public void onStart() { super.onStart(); mRefreshingReceiver = new BroadcastReceiver() { @Override//from www . j a v a2 s . c o m public void onReceive(Context context, Intent intent) { if (UpdaterService.BROADCAST_ACTION_STATE_CHANGE.equals(intent.getAction())) { boolean updaterIsRefreshing = intent.getBooleanExtra(UpdaterService.EXTRA_REFRESHING, false); if (!updaterIsRefreshing) { mRecyclerView.getAdapter().notifyDataSetChanged(); if (mSwiper != null) { mSwiper.setRefreshing(false); } } } } }; mContext.registerReceiver(mRefreshingReceiver, new IntentFilter(UpdaterService.BROADCAST_ACTION_STATE_CHANGE)); }
From source file:com.example.hackinghealthclinification.app.ClinificationApp.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_clinification_app); initializeLaunchButtons();// w ww. j av a2 s .co m mIsRegistered = false; // check if BroadcastReceiver registered IntentFilter filterSmsReceived = new IntentFilter("android.provider.Telephony.SMS_RECEIVED"); final SMSConfirmDialog.ConfirmDialogListener mListener = new SMSConfirmDialog.ConfirmDialogListener() { @Override public void onDialogPositiveClick(SMSConfirmDialog c) { // mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("yes" // + mPhoneNumber))); SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(mServerNumber, null, "yes", null, null); } @Override public void onDialogNegativeClick(SMSConfirmDialog c) { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(mServerNumber, null, "no", null, null); } }; mReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { mContext = context; Bundle pudsBundle = intent.getExtras(); Object[] pdus = (Object[]) pudsBundle.get("pdus"); SmsMessage messages = SmsMessage.createFromPdu((byte[]) pdus[0]); Log.i("Error with SMS ::: ", messages.getMessageBody()); if (messages.getMessageBody().contains(SMS_TRIGGER_KEY)) { mPhoneNumber = messages.getOriginatingAddress(); SMSConfirmDialog dialog = new SMSConfirmDialog(mListener, "Will you accept the new appointment: " + "\n" + messages.getMessageBody(), "Yes", "No"); dialog.show(getSupportFragmentManager(), null); } } }; this.registerReceiver(mReceiver, filterSmsReceived); mIsRegistered = true; }
From source file:com.nadmm.airports.aeronav.DtppFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mFilter = new IntentFilter(); mFilter.addAction(DtppService.ACTION_CHECK_CHARTS); mFilter.addAction(DtppService.ACTION_GET_CHARTS); mReceiver = new BroadcastReceiver() { @Override/*from ww w . j a v a2 s . c o m*/ public void onReceive(Context context, Intent intent) { handleDtppBroadcast(intent); } }; mOnClickListener = new View.OnClickListener() { @Override public void onClick(View v) { String path = (String) v.getTag(R.id.DTPP_PDF_PATH); if (path == null) { String pdfName = (String) v.getTag(R.id.DTPP_PDF_NAME); getTppChart(pdfName); } else { startPdfViewer(path); } } }; }
From source file:com.telestax.mayday_customer.fragment.CustomerSupportFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View viewInfo = inflater.inflate(R.layout.customer_support, container, false); // Initialize UI mImageViewCustomerMayDayCall = (ImageView) viewInfo.findViewById(R.id.imageView_customer_two_mayday); ImageView imageViewCustomerSupportBack = (ImageView) viewInfo .findViewById(R.id.imageView_customer_support_back); TextView textViewSupport = (TextView) viewInfo.findViewById(R.id.customer_support); textViewSupport.setOnClickListener(this); mImageViewCustomerMayDayCall.setOnClickListener(this); imageViewCustomerSupportBack.setOnClickListener(this); String mayDayAction = MainActivity.getMaydaySharePref(getActivity()); if (mayDayAction != null) { if (mayDayAction.equalsIgnoreCase(Constant.YES)) { mImageViewCustomerMayDayCall.setVisibility(View.INVISIBLE); } else {//from ww w.j a v a 2s. c om mImageViewCustomerMayDayCall.setVisibility(View.VISIBLE); } } mInitReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mImageViewCustomerMayDayCall.setVisibility(View.VISIBLE); } }; //Register broadcast receiver LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mInitReceiver, new IntentFilter(Constant.BROADCAST_INTENT)); return viewInfo; }
From source file:com.nadmm.airports.wx.PirepFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);/*from www . j a va 2 s. c om*/ mFilter = new IntentFilter(); mFilter.addAction(mAction); mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(mAction)) { String type = intent.getStringExtra(NoaaService.TYPE); if (type.equals(NoaaService.TYPE_TEXT)) { showPirep(intent); } } } }; }
From source file:com.facebook.CustomTabMainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Custom Tab Redirects should not be creating a new instance of this activity if (CustomTabActivity.CUSTOM_TAB_REDIRECT_ACTION.equals(getIntent().getAction())) { setResult(RESULT_CANCELED);/*w ww . j av a 2s. c o m*/ finish(); return; } if (savedInstanceState == null) { Bundle parameters = getIntent().getBundleExtra(EXTRA_PARAMS); String chromePackage = getIntent().getStringExtra(EXTRA_CHROME_PACKAGE); CustomTab customTab = new CustomTab(OAUTH_DIALOG, parameters); customTab.openCustomTab(this, chromePackage); shouldCloseCustomTab = false; // This activity will receive a broadcast if it can't be opened from the back stack redirectReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // Remove the custom tab on top of this activity. Intent newIntent = new Intent(CustomTabMainActivity.this, CustomTabMainActivity.class); newIntent.setAction(REFRESH_ACTION); newIntent.putExtra(EXTRA_URL, intent.getStringExtra(EXTRA_URL)); newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(newIntent); } }; LocalBroadcastManager.getInstance(this).registerReceiver(redirectReceiver, new IntentFilter(CustomTabActivity.CUSTOM_TAB_REDIRECT_ACTION)); } }