Example usage for android.content BroadcastReceiver BroadcastReceiver

List of usage examples for android.content BroadcastReceiver BroadcastReceiver

Introduction

In this page you can find the example usage for android.content BroadcastReceiver BroadcastReceiver.

Prototype

public BroadcastReceiver() 

Source Link

Usage

From source file:com.seamusdawkins.gcmcustom.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*www  .j av a  2  s .c  o  m*/

    checkPrefsExists(this);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Not updated token yet", Snackbar.LENGTH_LONG).setAction("Action", null).show();

        }
    });

    mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar);
    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mRegistrationProgressBar.setVisibility(ProgressBar.GONE);

            PrefsGcm prefsGcm = PrefsGcm.getPrefsHelper();
            boolean sentToken = prefsGcm.getPref(PrefsGcm.PREF_SENT_TOKEN_TO_SERVER, false);

            if (sentToken) {
                String token = prefsGcm.getPref(PrefsGcm.PREF_REGISTRATION_ID);
                mInformationTextView
                        .setText(getString(R.string.gcm_send_message) + "\n\nGCM Registration Token: " + token);
            } else {
                mInformationTextView.setText(getString(R.string.token_error_message));
            }
        }
    };
    mInformationTextView = (TextView) findViewById(R.id.informationTextView);

    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }

}

From source file:com.ibm.iot.android.iotstarter.fragments.LogPagerFragment.java

/**
 * Called when the fragment is resumed./* ww w  . j av  a  2  s .  c o m*/
 */
@Override
public void onResume() {
    Log.d(TAG, ".onResume() entered");

    super.onResume();
    Context context = getActivity().getApplicationContext();

    ListView listView = (ListView) getActivity().findViewById(android.R.id.list);

    app = (IoTStarterApplication) getActivity().getApplication();
    app.setCurrentRunningActivity(TAG);
    app.setUnreadCount(0);

    listAdapter = new ArrayAdapter<String>(context, R.layout.list_item, app.getMessageLog());
    listView.setAdapter(listAdapter);

    if (broadcastReceiver == null) {
        Log.d(TAG, ".onResume() - Registering LogBroadcastReceiver");
        broadcastReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                Log.d(TAG, ".onReceive() - Received intent for logBroadcastReceiver");
                processIntent(intent);
            }
        };
    }

    getActivity().getApplicationContext().registerReceiver(broadcastReceiver,
            new IntentFilter(Constants.APP_ID + Constants.INTENT_LOG));

    // Set color to black in case it somehow was leftover from iot fragment?
    getView().setBackgroundColor(getResources().getColor(R.color.background_main));

    // initialise
    initializeLogActivity();
}

From source file:com.google.firebase.quickstart.firebasestorage.java.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();/*from   ww  w  .j ava  2 s.c o  m*/

    // Click listeners
    findViewById(R.id.buttonCamera).setOnClickListener(this);
    findViewById(R.id.buttonSignIn).setOnClickListener(this);
    findViewById(R.id.buttonDownload).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:au.org.ala.fielddata.mobile.ViewSavedRecordsActivity.java

@Override
public void onResume() {
    super.onResume();

    reload();//from  w ww  .  ja v a 2  s. c o  m

    uploadReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            reload();
        }
    };

    IntentFilter filter = new IntentFilter();
    filter.addAction(UploadService.UPLOAD_FAILED);
    filter.addAction(UploadService.UPLOADED);
    filter.addAction(UploadService.STATUS_CHANGE);

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(uploadReceiver, filter);
}

From source file:eu.power_switch.gui.fragment.configure_timer.ConfigureTimerDialogPage4TabbedSummaryFragment.java

@Nullable
@Override//from  www .  j  ava2  s . c o  m
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.dialog_fragment_configure_timer_page_4_summary, 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) {
            if (LocalBroadcastConstants.INTENT_TIMER_NAME_EXECUTION_TIME_CHANGED.equals(intent.getAction())) {
                currentExecutionTime = (Calendar) intent.getSerializableExtra("executionTime");
                currentName = intent.getStringExtra("name");

            } else if (LocalBroadcastConstants.INTENT_TIMER_EXECUTION_INTERVAL_CHANGED
                    .equals(intent.getAction())) {
                currentExecutionInterval = intent.getLongExtra("executionInterval", -1);
                currentExecutionDays = (ArrayList<WeekdayTimer.Day>) intent
                        .getSerializableExtra("executionDays");
                currentExecutionType = intent.getStringExtra("executionType");

            } else if (LocalBroadcastConstants.INTENT_TIMER_ACTIONS_CHANGED.equals(intent.getAction())) {
                currentActions = (ArrayList<Action>) intent.getSerializableExtra("actions");
            }

            updateUi();

            notifyConfigurationChanged();
        }
    };

    textViewName = (TextView) rootView.findViewById(R.id.textView_name);
    textViewTime = (TextView) rootView.findViewById(R.id.textView_time);
    textViewDays = (TextView) rootView.findViewById(R.id.textView_execution_days);
    textViewAction = (TextView) rootView.findViewById(R.id.textView_action);

    Bundle args = getArguments();
    if (args != null && args.containsKey(ConfigureTimerDialog.TIMER_ID_KEY)) {
        currentId = args.getLong(ConfigureTimerDialog.TIMER_ID_KEY);
        initializeTimerData(currentId);
    }

    checkSetupValidity();
    updateUi();

    return rootView;
}

From source file:eu.geopaparazzi.core.ui.dialogs.GpsInfoDialogFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    SensorManager sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    orientationSensor = new OrientationSensor(sensorManager, null);
    orientationSensor.register(getActivity(), SensorManager.SENSOR_DELAY_NORMAL);

    gpsServiceBroadcastReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            onGpsServiceUpdate(intent);//from   ww w  .  ja  v a 2  s .  c o m
        }
    };
    GpsServiceUtilities.registerForBroadcasts(getActivity(), gpsServiceBroadcastReceiver);
    GpsServiceUtilities.triggerBroadcast(getActivity());
}

From source file:io.techministry.android.fellowshipmissionchurch.ui.AudioMessagesFragment.java

private void initBroadcastReceiver() {
    broadcastReceiver = new BroadcastReceiver() {
        @Override// www .  j a  v  a2  s . c o m
        public void onReceive(Context context, Intent intent) {
            String broadcast_type = intent.getExtras().getString("broadcast_type");

            if (broadcast_type.toString().equals(FellowshipApplication.BROADCAST_DOWNLOAD_AUDIO_FAILED)) {
                Utilities.showToast(context, "Update failed");
            }

            if (broadcast_type.equals(FellowshipApplication.BROADCAST_PLAY_MEDIA_AT_POSITION)) {
                int position = intent.getExtras().getInt("position");
                Log.e("position", position + "-");
                playAudioFileFromServer(position);

            }

            if (broadcast_type.equals(FellowshipApplication.BROADCAST_PAUSE_MEDIA_AT_POSITION)) {
                int position = intent.getExtras().getInt("position");
                audioMessages.get(position).setIs_playing(false);
                updateList();
            }

            if (broadcast_type.toString().equals(FellowshipApplication.BROADCAST_DOWNLOAD_AUDIO_SUCCESSFUL)) {
                audioMessages.clear();
                audioMessages.addAll(FellowshipApplication.getInstance().audioMessages);
                initJCPlayer();
                updateList();
            }

        }
    };
}

From source file:com.telestax.mayday_customer.fragment.ProductFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View viewInfo = inflater.inflate(R.layout.product, container, false);

    ViewPager viewPager = (ViewPager) viewInfo.findViewById(R.id.view_pager);
    mDotsLayout = (LinearLayout) viewInfo.findViewById(R.id.viewPagerCountDots);

    mInitReceiver = new BroadcastReceiver() {
        @Override//from   www  .  ja  v a2  s .  c  o  m
        public void onReceive(Context context, Intent intent) {
            mImageViewCustomerMayDayCall.setVisibility(View.VISIBLE);
        }
    };

    //Register broadcast receiver
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mInitReceiver,
            new IntentFilter(Constant.BROADCAST_INTENT));

    // Initialize UI
    ImageView ImageViewProductOne = (ImageView) viewInfo.findViewById(R.id.imageView_product);
    ImageView ImageViewProductTwo = (ImageView) viewInfo.findViewById(R.id.imageView_product_two);
    ImageView ImageViewProductThree = (ImageView) viewInfo.findViewById(R.id.imageView_product_three);
    ImageView ImageViewProductFour = (ImageView) viewInfo.findViewById(R.id.imageView_product_four);
    ImageView ImageViewProductFive = (ImageView) viewInfo.findViewById(R.id.imageView_product_five);
    ImageView ImageViewProductSix = (ImageView) viewInfo.findViewById(R.id.imageView_product_six);
    ImageView ImageViewProductSeven = (ImageView) viewInfo.findViewById(R.id.imageView_product_seven);

    mImageViewCustomerMayDayCall = (ImageView) viewInfo.findViewById(R.id.imageView_customer_mayday);

    ImageViewProductOne.setOnClickListener(this);
    ImageViewProductTwo.setOnClickListener(this);
    ImageViewProductThree.setOnClickListener(this);
    ImageViewProductFour.setOnClickListener(this);
    ImageViewProductFive.setOnClickListener(this);
    ImageViewProductSix.setOnClickListener(this);
    ImageViewProductSeven.setOnClickListener(this);

    String mayDayAction = MainActivity.getMaydaySharePref(getActivity());
    if (mayDayAction != null) {
        if (mayDayAction.equalsIgnoreCase(Constant.YES)) {
            mImageViewCustomerMayDayCall.setVisibility(View.INVISIBLE);
        } else {
            mImageViewCustomerMayDayCall.setVisibility(View.VISIBLE);
        }
    }

    ImagePagerAdapter adapter = new ImagePagerAdapter();
    viewPager.setAdapter(adapter);
    mDotsLayout.setBaselineAligned(true);
    setUiPageViewController();

    // ViewPager slider event
    viewPager.setOnPageChangeListener(viewPagerPageChangeListener);

    mImageViewCustomerMayDayCall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final CharSequence[] items = { getResources().getString(R.string.video),
                    getResources().getString(R.string.instant_message), };

            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(getResources().getString(R.string.action));
            builder.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    if (item == 0) {
                        mCallBack.onVideoCall();
                        mImageViewCustomerMayDayCall.setVisibility(View.INVISIBLE);
                    } else if (item == 1) {
                        mCallBack.onChatMessage();
                        mImageViewCustomerMayDayCall.setVisibility(View.INVISIBLE);

                    }
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });
    return viewInfo;
}

From source file:com.esminis.server.library.service.server.installpackage.InstallerPackage.java

private void stopServer(Context context, ServerControl serverControl) {
    final CyclicBarrier barrier = new CyclicBarrier(2);
    final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override//from w ww.j ava 2  s. c  o  m
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction() == null
                    || !intent.getAction().equals(MainActivity.getIntentActionServerStatus(context))) {
                return;
            }
            final Bundle extras = intent.getExtras();
            if (extras == null || extras.containsKey("errorLine") || extras.getBoolean("running")) {
                return;
            }
            try {
                barrier.await();
            } catch (InterruptedException | BrokenBarrierException ignored) {
            }
        }
    };
    context.registerReceiver(receiver, new IntentFilter(MainActivity.getIntentActionServerStatus(context)));
    preferences.set(context, Preferences.SERVER_STARTED, false);
    serverControl.requestStop(null);
    try {
        barrier.await();
    } catch (InterruptedException | BrokenBarrierException ignored) {
    }
    context.unregisterReceiver(receiver);
}

From source file:de.spiritcroc.ownlog.ui.fragment.MultiSelectTagDialog.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LocalBroadcastManager.getInstance(getActivity())
            .registerReceiver(mTagBroadcastReceiver = new BroadcastReceiver() {
                @Override/*from ww w.j a v  a 2s .c  om*/
                public void onReceive(Context context, Intent intent) {
                    Parcelable item = intent.getParcelableExtra(Constants.EXTRA_TAG_ITEM);
                    if (!(item instanceof TagItem)) {
                        Log.w(TAG, "Received invalid tag item: " + item);
                        return;
                    }
                    switch (intent.getIntExtra(Constants.EXTRA_TAG_ACTION, -1)) {
                    case Constants.TAG_ACTION_ADD:
                        onAddTagResult((TagItem) item);
                        break;
                    case Constants.TAG_ACTION_EDIT:
                        onEditTagResult((TagItem) item);
                        break;
                    case Constants.TAG_ACTION_DELETE:
                        onDeleteTagResult((TagItem) item);
                        break;
                    default:
                        Log.w(TAG, "Received unknown tag action: "
                                + intent.getIntExtra(Constants.EXTRA_TAG_ACTION, -1));
                        break;
                    }
                }
            }, new IntentFilter(Constants.EVENT_TAG_UPDATE));
}