Example usage for android.content IntentFilter IntentFilter

List of usage examples for android.content IntentFilter IntentFilter

Introduction

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

Prototype

public IntentFilter(Parcel source) 

Source Link

Usage

From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java

@Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "OnCreate");

        locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
        toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
        connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
        telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        // Stop-detection PI
        stationaryAlarmPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_ALARM_ACTION), 0);
        registerReceiver(stationaryAlarmReceiver, new IntentFilter(STATIONARY_ALARM_ACTION));

        // Stationary region PI
        stationaryRegionPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_REGION_ACTION),
                PendingIntent.FLAG_CANCEL_CURRENT);
        registerReceiver(stationaryRegionReceiver, new IntentFilter(STATIONARY_REGION_ACTION));

        // Stationary location monitor PI
        stationaryLocationPollingPI = PendingIntent.getBroadcast(this, 0,
                new Intent(STATIONARY_LOCATION_MONITOR_ACTION), 0);
        registerReceiver(stationaryLocationMonitorReceiver, new IntentFilter(STATIONARY_LOCATION_MONITOR_ACTION));

        // One-shot PI (TODO currently unused)
        singleUpdatePI = PendingIntent.getBroadcast(this, 0, new Intent(SINGLE_LOCATION_UPDATE_ACTION),
                PendingIntent.FLAG_CANCEL_CURRENT);
        registerReceiver(singleUpdateReceiver, new IntentFilter(SINGLE_LOCATION_UPDATE_ACTION));

        //////from   w  w w  . j a  v  a 2 s  .com
        // DISABLED
        // Listen to Cell-tower switches (NOTE does not operate while suspended)
        //telephonyManager.listen(phoneStateListener, LISTEN_CELL_LOCATION);
        //

        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

        wakeLock.acquire();

        // Location criteria
        criteria = new Criteria();
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setSpeedRequired(true);
        criteria.setCostAllowed(true);
    }

From source file:com.polyvi.xface.extension.XMessagingExt.java

private void regMsgReceiver() {
    getContext().registerReceiver(mMsgReceiveBroadcaseReveiver, new IntentFilter(INTENT_ACTION));
}

From source file:com.netease.qa.emmagee.service.EmmageeService.java

@Override
public void onCreate() {
    Log.i(LOG_TAG, "service onCreate");
    super.onCreate();
    isServiceStop = false;/*from w  w  w. j a v  a2 s  . co  m*/
    isStop = false;
    fpsInfo = new FpsInfo();
    memoryInfo = new MemoryInfo();
    procInfo = new ProcessInfo();
    fomart = new DecimalFormat();
    fomart.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    fomart.setGroupingUsed(false);
    fomart.setMaximumFractionDigits(2);
    fomart.setMinimumFractionDigits(0);
    des = new EncryptData("emmagee");
    currentInfo = new CurrentInfo();
    statusBarHeight = getStatusBarHeight();
    batteryBroadcast = new BatteryInfoBroadcastReceiver();
    registerReceiver(batteryBroadcast, new IntentFilter(BATTERY_CHANGED));
}

From source file:com.laquysoft.droidconnl.Hunt.java

/** Generates the entire hunt structure from JSON */
Hunt(String jsonString, Resources res, Context context) {

    //set filter to only when download is complete and register broadcast receiver
    IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
    context.registerReceiver(downloadReceiver, filter);
    soundManager = new SoundManager(context);
    achievementManager = new AchievementManager(res);

    try {//from  w  ww.  j a v  a 2s  . com
        clues = new HashMap<String, Clue>();
        clueList = new ArrayList<Clue>();
        tags = new HashMap<String, AHTag>();

        JSONObject huntObject = new JSONObject(jsonString);
        JSONArray clueObjList = huntObject.getJSONArray("clues");
        tagList = new ArrayList<AHTag>();

        int length = clueObjList.length();
        for (int i = 0; i < length; i++) {
            JSONObject clueObj = clueObjList.getJSONObject(i);

            Clue clue = new Clue(clueObj.getString("id"), clueObj.getString("displayName"),
                    clueObj.getString("displayText"), clueObj.getString("displayImage"));

            clue.shufflegroup = clueObj.getInt("shufflegroup");

            JSONArray tagObjList = clueObj.getJSONArray("tags");

            int tagLength = tagObjList.length();

            clueList.add(clue);

            for (int j = 0; j < tagLength; j++) {
                JSONObject tagObj = tagObjList.getJSONObject(j);
                AHTag tag = new AHTag(tagObj.getString("id"));
                tag.clueId = clue.id;
                clue.addTag(tag);
                tags.put(tag.id, tag);
                tagList.add(tag);
            }

            if (clueObj.has("question")) {
                clue.question = new TriviaQuestion(clueObj.getJSONObject("question"));
            }
        }
    } catch (Exception e) {
        if (e != null)
            Log.e("JSON Parser", "Error parsing Hunt data " + e.toString());
    }

    reset();
    restore(res, context);
}

From source file:com.securekey.sdk.sample.ReadCardActivity.java

private void enableForegroundDispatch() {
    Log.i("SDKSample", "enable foreground dispatch");
    if (NfcAdapter.getDefaultAdapter(this) != null) {
        try {/*from  w  w w  . j a va2  s. c  om*/
            NfcAdapter.getDefaultAdapter(this).enableForegroundDispatch(this,
                    PendingIntent.getActivity(this, 0,
                            new Intent(this, this.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0),
                    new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED) }, new String[][] {
                            new String[] { NfcA.class.getName() }, new String[] { NfcB.class.getName() } });
        } catch (Exception e) {
            Log.i("SDKSample", "enableForegroundDispatch failed");
        }
    }
}

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

/**
 * ? ?UI???UI??????? activityList.size() <= 0 ????????Activity Stack
 *//*from  w ww .  j av a 2 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);

        }

    });
}

From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java

private void regMsgReceiver() {
    mContext.registerReceiver(mMsgReceiveBroadcaseReceiver, new IntentFilter(INTENT_ACTION));
}

From source file:com.example.run_tracker.RunFragment.java

public void onResume() {
    // when the user returns to RunFragment we must bring everything back
    // from TrackingService
    super.onResume();
    // redraw the line by getting the list of waypoints from service
    if (((MainActivity) getActivity()).getMyService() != null)

    {//  w  w w . j  a va 2 s  . c om
        if (((MainActivity) getActivity()).getMyService().isStarted()) {
            mStart.setEnabled(false);
            // get the list of point from service and redraw the line
            options = new PolylineOptions();
            options.addAll(((MainActivity) getActivity()).getMyService().getCoursePoints());
            options.width(3);
            options.color(Color.GREEN);
            mMap.addPolyline(options);
            mMap.moveCamera(CameraUpdateFactory
                    .newLatLngZoom(((MainActivity) getActivity()).getMyService().getLastPoint(), ZOOM_LEVEL));
            mDistanceText.setText(((MainActivity) getActivity()).getMyService().getDistance() + " m");
        }
        if (((((MainActivity) getActivity()).getMyService().isStarted()))) {
            mStatus.setText(R.string.Running);
            mStatus.setTextColor(Color.GREEN);
        }

    }
    // start listening to location changes
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mMessageReceiver,
            new IntentFilter("location_changed"));
}

From source file:com.ariesmcrae.eskwela.celebtweet.MainActivity.java

/** Register the BroadcastReceiver */
@Override//w  w  w .  j  ava  2s. c o  m
protected void onResume() {
    super.onResume();

    if (mRefreshReceiver != null) {
        // mRefreshReciver is null if mIsFresh == true, therefore we need to check for null.
        registerReceiver(mRefreshReceiver, new IntentFilter(DATA_REFRESHED_ACTION));
    }
}