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:eu.power_switch.gui.fragment.ApartmentFragment.java

@Override
public void onCreateViewEvent(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_apartment, container, false);
    setHasOptionsMenu(true);//from ww  w .ja va  2s  .  co  m

    final RecyclerViewFragment recyclerViewFragment = this;
    recyclerViewApartments = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    apartmentArrayAdapter = new ApartmentRecyclerViewAdapter(getActivity(), apartments);

    recyclerViewApartments.setAdapter(apartmentArrayAdapter);
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(),
            StaggeredGridLayoutManager.VERTICAL);
    recyclerViewApartments.setLayoutManager(layoutManager);
    apartmentArrayAdapter.setOnItemClickListener(new ApartmentRecyclerViewAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(View itemView, int position) {
            final Apartment apartment = apartments.get(position);

            SmartphonePreferencesHandler.setCurrentApartmentId(apartment.getId());

            for (Apartment currentApartment : apartments) {
                if (currentApartment.getId().equals(apartment.getId())) {
                    currentApartment.setActive(true);
                } else {
                    currentApartment.setActive(false);
                }
            }

            apartmentArrayAdapter.notifyDataSetChanged();
        }
    });
    apartmentArrayAdapter
            .setOnItemLongClickListener(new ApartmentRecyclerViewAdapter.OnItemLongClickListener() {
                @Override
                public void onItemLongClick(View itemView, final int position) {
                    Apartment apartment = apartments.get(position);

                    ConfigureApartmentDialog configureApartmentDialog = ConfigureApartmentDialog
                            .newInstance(apartment.getId());
                    configureApartmentDialog.setTargetFragment(recyclerViewFragment, 0);
                    configureApartmentDialog.show(getFragmentManager(), null);
                }
            });

    fab = (FloatingActionButton) rootView.findViewById(R.id.add_fab);
    fab.setImageDrawable(IconicsHelper.getAddIcon(getActivity(),
            ContextCompat.getColor(getContext(), android.R.color.white)));
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                ConfigureApartmentDialog configureApartmentDialog = new ConfigureApartmentDialog();
                configureApartmentDialog.setTargetFragment(recyclerViewFragment, 0);
                configureApartmentDialog.show(getFragmentManager(), null);
            } catch (Exception e) {
                StatusMessageHandler.showErrorMessage(recyclerViewFragment.getRecyclerView(), e);
            }
        }
    });

    // BroadcastReceiver to get notifications from background service if room data has changed
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(this, "received intent: " + intent.getAction());
            updateUI();
        }
    };
}

From source file:com.keepassdroid.EntryActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mShowPassword = !prefs.getBoolean(getString(R.string.maskpass_key),
            getResources().getBoolean(R.bool.maskpass_default));

    super.onCreate(savedInstanceState);
    setEntryView();/* ww  w .  j a  va  2 s  .c o  m*/

    Context appCtx = getApplicationContext();
    dateFormat = android.text.format.DateFormat.getDateFormat(appCtx);
    timeFormat = android.text.format.DateFormat.getTimeFormat(appCtx);

    Database db = App.getDB();
    // Likely the app has been killed exit the activity 
    if (!db.Loaded()) {
        finish();
        return;
    }
    readOnly = db.readOnly;

    setResult(KeePass.EXIT_NORMAL);

    Intent i = getIntent();
    UUID uuid = Types.bytestoUUID(i.getByteArrayExtra(KEY_ENTRY));
    mPos = i.getIntExtra(KEY_REFRESH_POS, -1);
    assert (uuid != null);

    mEntry = db.pm.entries.get(uuid);
    if (mEntry == null) {
        Toast.makeText(this, R.string.entry_not_found, Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    // Refresh Menu contents in case onCreateMenuOptions was called before mEntry was set
    this.invalidateOptionsMenu();

    // Update last access time.
    mEntry.touch(false, false);

    fillData(false);

    setupEditButtons();

    // Notification Manager
    NotificationUtil.createChannels(getApplicationContext());
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    if (mEntry.getPassword().length() > 0) {
        // only show notification if password is available
        Notification password = getNotification(Intents.COPY_PASSWORD, R.string.copy_password);
        mNM.notify(NOTIFY_PASSWORD, password);
    }

    if (mEntry.getUsername().length() > 0) {
        // only show notification if username is available
        Notification username = getNotification(Intents.COPY_USERNAME, R.string.copy_username);
        mNM.notify(NOTIFY_USERNAME, username);
    }

    mIntentReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (action.equals(Intents.COPY_USERNAME)) {
                String username = mEntry.getUsername();
                if (username.length() > 0) {
                    timeoutCopyToClipboard(username);
                }
            } else if (action.equals(Intents.COPY_PASSWORD)) {
                String password = new String(mEntry.getPassword());
                if (password.length() > 0) {
                    timeoutCopyToClipboard(new String(mEntry.getPassword()));
                }
            }
        }
    };

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intents.COPY_USERNAME);
    filter.addAction(Intents.COPY_PASSWORD);
    registerReceiver(mIntentReceiver, filter);
}

From source file:alaindc.crowdroid.View.MainActivity.java

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

    listGeofenceCircle = new HashMap<>();
    listCircles = new HashMap<>();

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    textView = (TextView) findViewById(R.id.textView);
    textView.setMovementMethod(new ScrollingMovementMethod());

    sensorsCheckbox = (CheckBox) findViewById(R.id.sensorscheck);
    requestsCheckbox = (CheckBox) findViewById(R.id.requestscheck);

    this.settingsButton = (Button) findViewById(R.id.settbutton);
    settingsButton.setOnClickListener(new View.OnClickListener() {
        @Override//  w ww.  j a v a2s .  c o  m
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), StakeholdersActivity.class);
            startActivity(i);
        }
    });

    this.requestButton = (Button) findViewById(R.id.button);
    requestButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // TODO: Disable
            //requestButton.setEnabled(false);

            // Start sending messages to server
            Intent serviceIntent[] = new Intent[Constants.MONITORED_SENSORS.length];
            for (int i = 0; i < Constants.MONITORED_SENSORS.length; i++) {
                serviceIntent[i] = new Intent(getApplicationContext(), SendIntentService.class);
                serviceIntent[i].setAction(Constants.ACTION_SENDDATA + Constants.MONITORED_SENSORS[i]);
                serviceIntent[i].putExtra(Constants.EXTRA_TYPE_OF_SENSOR_TO_SEND,
                        Constants.MONITORED_SENSORS[i]); // TODO Here set to send all kind of sensor for start
                getApplicationContext().startService(serviceIntent[i]);

            }
        }
    });

    this.sensorButton = (Button) findViewById(R.id.buttonLoc);
    sensorButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            sensorButton.setEnabled(false);

            // Clear preferences
            getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE).edit().clear().commit();

            // Start service for PhoneListener
            Intent phoneListIntent = new Intent(getApplicationContext(), NeverSleepService.class);
            getApplicationContext().startService(phoneListIntent);

            // Start intent service for update position
            Intent posintent = new Intent(getApplicationContext(), PositionIntentService.class);
            getApplicationContext().startService(posintent);

            // Start intent service for update sensors
            Intent sensorintent = new Intent(getApplicationContext(), SensorsIntentService.class);
            sensorintent.setAction(Constants.INTENT_START_SENSORS);
            getApplicationContext().startService(sensorintent);

            // Start intent service for update amplitude sensing
            Intent amplintent = new Intent(getApplicationContext(), SensorsIntentService.class);
            amplintent.setAction(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE);
            getApplicationContext().startService(amplintent);
        }
    });

    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Constants.INTENT_RECEIVED_DATA)) {
                String response = intent.getStringExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA);
                if (response != null && requestsCheckbox.isChecked())
                    textView.append(response + "\n");
            } else if (intent.getAction().equals(Constants.INTENT_UPDATE_POS)) {
                setLocationAndMap();
            } else if (intent.getAction().equals(Constants.INTENT_UPDATE_SENSORS)) {
                String response = intent.getStringExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA);
                if (response != null && sensorsCheckbox.isChecked())
                    textView.append(response + "\n");
            } else if (intent.getAction().equals(Constants.INTENT_UPDATE_GEOFENCEVIEW)) { // Geofencing
                addGeofenceView(intent.getIntExtra(Constants.INTENT_GEOFENCEEXTRA_SENSOR, 0),
                        intent.getDoubleExtra(Constants.INTENT_GEOFENCEEXTRA_LATITUDE, 0),
                        intent.getDoubleExtra(Constants.INTENT_GEOFENCEEXTRA_LONGITUDE, 0),
                        intent.getFloatExtra(Constants.INTENT_GEOFENCEEXTRA_RADIUS, 100));
            } else {
                Log.d("", "");
            }
        }
    };

    IntentFilter rcvDataIntFilter = new IntentFilter(Constants.INTENT_RECEIVED_DATA);
    IntentFilter updatePosIntFilter = new IntentFilter(Constants.INTENT_UPDATE_POS);
    IntentFilter updateSenseIntFilter = new IntentFilter(Constants.INTENT_UPDATE_SENSORS);
    IntentFilter updateGeofenceViewIntFilter = new IntentFilter(Constants.INTENT_UPDATE_GEOFENCEVIEW);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, rcvDataIntFilter);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updatePosIntFilter);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updateSenseIntFilter);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updateGeofenceViewIntFilter);

}

From source file:com.easemob.chatui.DemoHXSDKHelper.java

/**
 * ?/*from   www.  j a va 2 s.  co  m*/
 * ?UI???UI???????
 * activityList.size() <= 0 ????????Activity Stack
 */
protected void initEventListener() {
    eventListener = new EMEventListener() {
        private BroadcastReceiver broadCastReceiver = null;

        @Override
        public void onEvent(EMNotifierEvent event) {
            EMMessage message = null;
            if (event.getData() instanceof EMMessage) {
                message = (EMMessage) event.getData();
                EMLog.d(TAG, "receive the event : " + event.getEvent() + ",id : " + message.getMsgId());
            }

            switch (event.getEvent()) {
            case EventNewMessage:
                //????UI,????
                if (activityList.size() <= 0) {
                    HXSDKHelper.getInstance().getNotifier().onNewMsg(message);
                }
                break;
            case EventOfflineMessage:
                if (activityList.size() <= 0) {
                    EMLog.d(TAG, "received offline messages");
                    List<EMMessage> messages = (List<EMMessage>) event.getData();
                    HXSDKHelper.getInstance().getNotifier().onNewMesg(messages);
                }
                break;

            case EventNewCMDMessage: {

                EMLog.d(TAG, "??");
                //??body
                CmdMessageBody cmdMsgBody = (CmdMessageBody) message.getBody();
                final String action = cmdMsgBody.action;//?action

                //? ?
                //message.getStringAttribute("");
                EMLog.d(TAG, String.format("??action:%s,message:%s", action, message.toString()));
                final String str = appContext.getString(R.string.receive_the_passthrough);

                final String CMD_TOAST_BROADCAST = "easemob.demo.cmd.toast";
                IntentFilter cmdFilter = new IntentFilter(CMD_TOAST_BROADCAST);

                if (broadCastReceiver == null) {
                    broadCastReceiver = new BroadcastReceiver() {

                        @Override
                        public void onReceive(Context context, Intent intent) {
                            // TODO Auto-generated method stub
                            Toast.makeText(appContext, intent.getStringExtra("cmd_value"), Toast.LENGTH_SHORT)
                                    .show();
                        }
                    };

                    //
                    appContext.registerReceiver(broadCastReceiver, cmdFilter);
                }

                Intent broadcastIntent = new Intent(CMD_TOAST_BROADCAST);
                broadcastIntent.putExtra("cmd_value", str + action);
                appContext.sendBroadcast(broadcastIntent, null);

                break;
            }
            case EventDeliveryAck:
                message.setDelivered(true);
                break;
            case EventReadAck:
                message.setAcked(true);
                break;
            // add other events in case you are interested in
            default:
                break;
            }

        }
    };

    EMChatManager.getInstance().registerEventListener(eventListener);

    EMChatManager.getInstance().addChatRoomChangeListener(new EMChatRoomChangeListener() {
        private final static String ROOM_CHANGE_BROADCAST = "easemob.demo.chatroom.changeevent.toast";
        private final IntentFilter filter = new IntentFilter(ROOM_CHANGE_BROADCAST);
        private boolean registered = false;

        private void showToast(String value) {
            if (!registered) {
                //
                appContext.registerReceiver(new BroadcastReceiver() {

                    @Override
                    public void onReceive(Context context, Intent intent) {
                        Toast.makeText(appContext, intent.getStringExtra("value"), Toast.LENGTH_SHORT).show();
                    }

                }, filter);

                registered = true;
            }

            Intent broadcastIntent = new Intent(ROOM_CHANGE_BROADCAST);
            broadcastIntent.putExtra("value", value);
            appContext.sendBroadcast(broadcastIntent, null);
        }

        @Override
        public void onChatRoomDestroyed(String roomId, String roomName) {
            showToast(" room : " + roomId + " with room name : " + roomName + " was destroyed");
            Log.i("info", "onChatRoomDestroyed=" + roomName);
        }

        @Override
        public void onMemberJoined(String roomId, String participant) {
            showToast("member : " + participant + " join the room : " + roomId);
            Log.i("info", "onmemberjoined=" + participant);

        }

        @Override
        public void onMemberExited(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " leave the room : " + roomId + " room name : " + roomName);
            Log.i("info", "onMemberExited=" + participant);

        }

        @Override
        public void onMemberKicked(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " was kicked from the room : " + roomId + " room name : "
                    + roomName);
            Log.i("info", "onMemberKicked=" + participant);

        }

    });
}

From source file:com.mifos.mifosxdroid.activity.pathtracking.PathTrackingService.java

public void createNotificationReceiver() {
    notificationReceiver = new BroadcastReceiver() {
        @Override/* w  ww .j  a  v a  2s  .  c om*/
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Constants.STOP_TRACKING.equals(action)) {
                onDestroy();
            }
        }
    };
    registerReceiver(notificationReceiver, new IntentFilter(Constants.STOP_TRACKING));
}

From source file:com.cellbots.eyes.EyesActivity.java

/** Called when the activity is first created. */
@Override/*from  ww  w.jav  a 2 s  . c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    Log.e("remote eyes", "started");
    super.onCreate(savedInstanceState);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE | PowerManager.ACQUIRE_CAUSES_WAKEUP,
            "Cellbot Eyes");
    mWakeLock.acquire();

    mTorchMode = false;

    out = new ByteArrayOutputStream();

    if ((getIntent() != null) && (getIntent().getData() != null)) {
        putUrl = getIntent().getData().toString();
        server = putUrl.replace("http://", "");
        server = server.substring(0, server.indexOf("/"));
        Bundle extras = getIntent().getExtras();
        if ((extras != null) && (extras.getBoolean("TORCH", false))) {
            mTorchMode = true;
        }
    } else {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        putUrl = prefs.getString("REMOTE_EYES_PUT_URL", "");
        Log.e("prefs", putUrl);
        if (putUrl.length() < 1) {
            Intent i = new Intent();
            i.setClass(this, PrefsActivity.class);
            startActivity(i);
            finish();
            return;
        } else {
            server = putUrl.replace("http://", "");
            server = server.substring(0, server.indexOf("/"));
        }
    }

    resetConnection();
    mHttpState = new HttpState();

    setContentView(R.layout.eyes_main);
    mPreview = (SurfaceView) findViewById(R.id.eyes_preview);
    mHolder = mPreview.getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mPreview.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            setTorchMode(!mTorchMode);
        }
    });

    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean useTorch = intent.getBooleanExtra("TORCH", false);
            boolean shouldTakePicture = intent.getBooleanExtra("PICTURE", false);
            setTorchMode(useTorch);
            setTakePicture(shouldTakePicture);
        }
    };

    this.registerReceiver(mReceiver, new IntentFilter(EyesActivity.EYES_COMMAND));

    mFrame = (FrameLayout) findViewById(R.id.eyes_frame);
    mWebView = new WebView(this);
    mWebView.getSettings().setJavaScriptEnabled(true);
    // Use this if you want to load content locally
    // mWebView.loadUrl("content://com.cellbot.localpersonas/default/index.html");
    mWebView.loadUrl("http://personabots.appspot.com/expressions/tuby");

    mFrame.addView(mWebView);
}

From source file:com.perm.DoomPlay.AbstractReceiver.java

protected void createBroadcastRec() {
    broadcastReceiver = new BroadcastReceiver() {
        @Override/*from   w  w  w .  ja va2  s  . c  om*/
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (action.equals(PlayingService.actionTrackChanged)
                    || (action.equals(PlayingService.actionIconPlay)
                            || action.equals(PlayingService.actionIconPause))) {
                updateActionBar();
            }
        }
    };
    intentFilter = new IntentFilter(PlayingService.actionTrackChanged);
    intentFilter.addAction(PlayingService.actionIconPause);
    intentFilter.addAction(PlayingService.actionIconPlay);
    registerReceiver(broadcastReceiver, intentFilter);
    isRegister = true;
}

From source file:com.woodblockwithoutco.quickcontroldock.model.impl.actions.flashlight.FlashlightService.java

@Override
public void onCreate() {

    sIsRunning = true;/*from w  ww .  j  av  a2s  .  com*/

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle(getResources().getString(R.string.persistent_flash_active));
    builder.setContentText(getResources().getString(R.string.persistent_flash_active_tap));
    builder.setSmallIcon(R.drawable.ic_persistent_flash);

    builder.setContentIntent(
            PendingIntent.getBroadcast(this, -1, new Intent(getPackageName() + ".STOP_FLASH"), 0));
    startForeground(NOTIFICATION_ID, builder.build());

    mContainer = new LinearLayout(getApplicationContext());
    LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    mContainer.setLayoutParams(lparams);
    mContainer.setOrientation(LinearLayout.VERTICAL);

    mTurnOffButton = new ImageButton(getApplicationContext());
    mTurnOffButton.setImageResource(R.drawable.ic_persistent_flash);
    mTurnOffButton.setBackgroundColor(0x80000000);
    mTurnOffButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            stopSelf();
        }
    });

    mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    WindowManager.LayoutParams params = new WindowManager.LayoutParams();
    params.type = ConstantHolder.getLockscreenType();
    params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    params.x = 0;
    params.y = 0;
    params.width = WindowManager.LayoutParams.WRAP_CONTENT;
    params.height = params.width;
    params.gravity = Gravity.CENTER;
    params.format = PixelFormat.TRANSLUCENT;

    mContainer.addView(mTurnOffButton);

    String method = TogglesResolver.getFlashlightType(getApplicationContext());

    if (method.equals("default")) {
        mDummySurfaceView = new SurfaceView(getApplicationContext());
        mDummySurfaceView.setAlpha(0.01f);
        ViewGroup.LayoutParams sparams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 1);
        mDummySurfaceView.setLayoutParams(sparams);
        mFlashManipulator = new DefaultFlashlightManipulator(mDummySurfaceView);
        mContainer.addView(mDummySurfaceView);
    } else if (method.equals("htc")) {
        mFlashManipulator = new HTCFlashlightManipulator();
    } else if (method.equals("nosurfaceview")) {
        mFlashManipulator = new NoSurfaceViewFlashlightManipulator();
    } else {
        mDummySurfaceView = new SurfaceView(getApplicationContext());
        mDummySurfaceView.setAlpha(0.01f);
        ViewGroup.LayoutParams sparams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 1);
        mDummySurfaceView.setLayoutParams(sparams);
        mFlashManipulator = new DefaultFlashlightManipulator(mDummySurfaceView);
        mContainer.addView(mDummySurfaceView);
    }

    mWindowManager.addView(mContainer, params);

    mHandler = new Handler();
    mActor = new Runnable() {
        @Override
        public void run() {
            mFlashManipulator.turnFlashlightOn();
        }
    };

    mScreenOffReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mFlashManipulator.turnFlashlightOff();
            mHandler.postDelayed(mActor, 200);
        }
    };

    mStopServiceReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mFlashManipulator.turnFlashlightOff();
            stopSelf();
        }
    };
    registerReceiver(mScreenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
    registerReceiver(mStopServiceReceiver, new IntentFilter(getPackageName() + ".STOP_FLASH"));
}

From source file:aenadon.wienerlinienalarm.activities.MainActivity.java

private void setupAlarmTriggeredReceiver() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Keys.Intent.REFRESH_LIST);

    alarmTriggeredReceiver = new BroadcastReceiver() {
        @Override//from www . j a v  a2  s .co m
        public void onReceive(Context context, Intent intent) {
            tabAdapter.notifyDataSetChanged();
        }
    };
    registerReceiver(alarmTriggeredReceiver, intentFilter);
}

From source file:com.grass.caishi.cc.DemoHXSDKHelper.java

/**
 * ? ?UI???UI??????? activityList.size() <= 0 ????????Activity Stack
 *//*  w ww  .j a v a2 s  .  c o m*/
protected void initEventListener() {
    eventListener = new EMEventListener() {
        private BroadcastReceiver broadCastReceiver = null;

        @Override
        public void onEvent(EMNotifierEvent event) {
            EMMessage message = null;
            if (event.getData() instanceof EMMessage) {
                message = (EMMessage) event.getData();
                EMLog.d(TAG, "receive the event : " + event.getEvent() + ",id : " + message.getMsgId());
            }

            switch (event.getEvent()) {
            case EventNewMessage:
                // ????UI,????
                if (activityList.size() <= 0) {
                    HXSDKHelper.getInstance().getNotifier().onNewMsg(message);
                }
                break;
            case EventOfflineMessage:
                if (activityList.size() <= 0) {
                    EMLog.d(TAG, "received offline messages");
                    List<EMMessage> messages = (List<EMMessage>) event.getData();
                    HXSDKHelper.getInstance().getNotifier().onNewMesg(messages);
                }
                break;
            // below is just giving a example to show a cmd toast, the app
            // should not follow this
            // so be careful of this
            case EventNewCMDMessage: {

                EMLog.d(TAG, "??");
                // ??body
                CmdMessageBody cmdMsgBody = (CmdMessageBody) message.getBody();
                final String action = cmdMsgBody.action;// ?action

                // ? ?
                // message.getStringAttribute("");
                EMLog.d(TAG, String.format("??action:%s,message:%s", action, message.toString()));
                final String str = appContext.getString(R.string.receive_the_passthrough);

                final String CMD_TOAST_BROADCAST = "easemob.demo.cmd.toast";
                IntentFilter cmdFilter = new IntentFilter(CMD_TOAST_BROADCAST);

                if (broadCastReceiver == null) {
                    broadCastReceiver = new BroadcastReceiver() {

                        @Override
                        public void onReceive(Context context, Intent intent) {
                            // TODO Auto-generated method stub
                            Toast.makeText(appContext, intent.getStringExtra("cmd_value"), Toast.LENGTH_SHORT)
                                    .show();
                        }
                    };

                    // 
                    appContext.registerReceiver(broadCastReceiver, cmdFilter);
                }

                Intent broadcastIntent = new Intent(CMD_TOAST_BROADCAST);
                broadcastIntent.putExtra("cmd_value", str + action);
                appContext.sendBroadcast(broadcastIntent, null);

                break;
            }
            case EventDeliveryAck:
                message.setDelivered(true);
                break;
            case EventReadAck:
                message.setAcked(true);
                break;
            // add other events in case you are interested in
            default:
                break;
            }

        }
    };

    EMChatManager.getInstance().registerEventListener(eventListener);

    EMChatManager.getInstance().addChatRoomChangeListener(new EMChatRoomChangeListener() {
        private final static String ROOM_CHANGE_BROADCAST = "easemob.demo.chatroom.changeevent.toast";
        private final IntentFilter filter = new IntentFilter(ROOM_CHANGE_BROADCAST);
        private boolean registered = false;

        private void showToast(String value) {
            if (!registered) {
                // 
                appContext.registerReceiver(new BroadcastReceiver() {

                    @Override
                    public void onReceive(Context context, Intent intent) {
                        Toast.makeText(appContext, intent.getStringExtra("value"), Toast.LENGTH_SHORT).show();
                    }

                }, filter);

                registered = true;
            }

            Intent broadcastIntent = new Intent(ROOM_CHANGE_BROADCAST);
            broadcastIntent.putExtra("value", value);
            appContext.sendBroadcast(broadcastIntent, null);
        }

        @Override
        public void onChatRoomDestroyed(String roomId, String roomName) {
            showToast(" room : " + roomId + " with room name : " + roomName + " was destroyed");
            Log.i("info", "onChatRoomDestroyed=" + roomName);
        }

        @Override
        public void onMemberJoined(String roomId, String participant) {
            showToast("member : " + participant + " join the room : " + roomId);
            Log.i("info", "onmemberjoined=" + participant);

        }

        @Override
        public void onMemberExited(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " leave the room : " + roomId + " room name : " + roomName);
            Log.i("info", "onMemberExited=" + participant);

        }

        @Override
        public void onMemberKicked(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " was kicked from the room : " + roomId + " room name : "
                    + roomName);
            Log.i("info", "onMemberKicked=" + participant);

        }

    });
}