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:fr.inria.ucn.collectors.NetworkStateCollector.java

private JSONObject getWifi(Context c) throws JSONException {
    WifiManager wm = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wi = wm.getConnectionInfo();

    // start a wifi AP scan
    Helpers.acquireWifiLock(c);/*w ww. j  a  v a  2s. c om*/
    IntentFilter filter = new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    c.registerReceiver(this, filter);
    wm.startScan();

    JSONObject o = new JSONObject();
    o.put("link_speed", wi.getLinkSpeed());
    o.put("link_speed_units", WifiInfo.LINK_SPEED_UNITS);
    o.put("signal_level", WifiManager.calculateSignalLevel(wi.getRssi(), 100));
    o.put("rssi", wi.getRssi());
    o.put("bssid", wi.getBSSID());
    o.put("ssid", wi.getSSID().replaceAll("\"", ""));
    o.put("mac", wi.getMacAddress());

    int ip = wi.getIpAddress();
    String ipstr = String.format(Locale.US, "%d.%d.%d.%d", (ip & 0xff), (ip >> 8 & 0xff), (ip >> 16 & 0xff),
            (ip >> 24 & 0xff));
    o.put("ip", ipstr);

    return o;
}

From source file:com.rjfun.cordova.sms.SMSPlugin.java

protected void createIncomingSMSReceiver() {
    Activity ctx = this.cordova.getActivity();
    this.mReceiver = new BroadcastReceiver() {

        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Log.d(LOGTAG, ("onRecieve: " + action));
            if (SMS_RECEIVED.equals(action)) {
                Bundle bundle;/*from w  w  w .  j a v  a 2 s.c  o  m*/
                if (SMSPlugin.this.mIntercept) {
                    this.abortBroadcast();
                }
                if ((bundle = intent.getExtras()) != null) {
                    Object[] pdus;
                    if ((pdus = (Object[]) bundle.get("pdus")).length != 0) {
                        for (int i = 0; i < pdus.length; ++i) {
                            SmsMessage sms = SmsMessage.createFromPdu((byte[]) ((byte[]) pdus[i]));
                            JSONObject json = SMSPlugin.this.getJsonFromSmsMessage(sms);
                            SMSPlugin.this.onSMSArrive(json);
                        }
                    }
                }
            }
        }
    };
    String[] filterstr = new String[] { SMS_RECEIVED };
    for (int i = 0; i < filterstr.length; ++i) {
        IntentFilter filter = new IntentFilter(filterstr[i]);
        filter.setPriority(100);
        ctx.registerReceiver(this.mReceiver, filter);
        Log.d(LOGTAG, ("broadcast receiver registered for: " + filterstr[i]));
    }
}

From source file:edu.missouri.bas.service.SensorService.java

@SuppressWarnings("deprecation")
@Override/*from   w w w .j  av  a2 s  .  c o  m*/
public void onCreate() {

    super.onCreate();
    Log.d(TAG, "Starting sensor service");
    mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
    soundsMap = new HashMap<Integer, Integer>();
    soundsMap.put(SOUND1, mSoundPool.load(this, R.raw.bodysensor_alarm, 1));
    soundsMap.put(SOUND2, mSoundPool.load(this, R.raw.voice_notification, 1));

    serviceContext = this;

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    bluetoothMacAddress = mBluetoothAdapter.getAddress();
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    //Get location manager
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    activityRecognition = new ActivityRecognitionScan(getApplicationContext());
    activityRecognition.startActivityRecognitionScan();

    mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    serviceWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SensorServiceLock");
    serviceWakeLock.acquire();

    //Initialize start time
    stime = System.currentTimeMillis();

    //Setup calendar object
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(stime);

    /*
     * Setup notification manager
     */

    notification = new Notification(R.drawable.icon2, "Recorded", System.currentTimeMillis());
    notification.defaults = 0;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent notifyIntent = new Intent(Intent.ACTION_MAIN);
    notifyIntent.setClass(this, MainActivity.class);

    /*
     * Display notification that service has started
     */
    notification.tickerText = "Sensor Service Running";
    PendingIntent contentIntent = PendingIntent.getActivity(SensorService.this, 0, notifyIntent,
            Notification.FLAG_ONGOING_EVENT);
    notification.setLatestEventInfo(SensorService.this, getString(R.string.app_name),
            "Recording service started at: " + cal.getTime().toString(), contentIntent);

    notificationManager.notify(SensorService.SERVICE_NOTIFICATION_ID, notification);

    // locationControl = new LocationControl(this, mLocationManager, 1000 * 60, 200, 5000);   

    IntentFilter activityResultFilter = new IntentFilter(XMLSurveyActivity.INTENT_ACTION_SURVEY_RESULTS);
    SensorService.this.registerReceiver(alarmReceiver, activityResultFilter);

    IntentFilter sensorDataFilter = new IntentFilter(SensorService.ACTION_SENSOR_DATA);
    SensorService.this.registerReceiver(alarmReceiver, sensorDataFilter);
    Log.d(TAG, "Sensor service created.");

    try {
        prepareIO();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    prepareAlarms();

    Intent startSensors = new Intent(SensorService.ACTION_START_SENSORS);
    this.sendBroadcast(startSensors);

    Intent scheduleCheckConnection = new Intent(SensorService.ACTION_SCHEDULE_CHECK);
    scheduleCheck = PendingIntent.getBroadcast(serviceContext, 0, scheduleCheckConnection, 0);
    mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            SystemClock.elapsedRealtime() + 1000 * 60 * 5, 1000 * 60 * 5, scheduleCheck);
    mLocationClient = new LocationClient(this, this, this);
}

From source file:com.hybris.mobile.app.commerce.CommerceApplicationBase.java

public void onCreate() {
    super.onCreate();
    mInstance = this;

    String urlBackend = getStringFromSharedPreferences(getString(R.string.preference_key_value_base_url), "");
    String catalogStore = getStringFromSharedPreferences(getString(R.string.preference_key_value_catalog_store),
            "");//  www . j  a v  a 2 s.com
    String catalogId = getStringFromSharedPreferences(getString(R.string.preference_key_value_catalog_id), "");
    String catalogMainCategory = getStringFromSharedPreferences(
            getString(R.string.preference_key_value_catalog_main_category_id), "");

    // Setting the default backend url
    if (StringUtils.isBlank(urlBackend)) {
        urlBackend = getString(R.string.url_backend);

        int index = ArrayUtils.indexOf(getResources().getStringArray(R.array.backend_url_values), urlBackend);

        // Update the settings
        setStringToSharedPreferences(getString(R.string.preference_key_value_base_url), urlBackend);
        setStringToSharedPreferences(getString(R.string.preference_key_key_base_url),
                getResources().getStringArray(R.array.backend_url_keys)[index]);
    }

    // Setting the default catalog
    if (StringUtils.isBlank(catalogStore)) {
        catalogStore = getString(R.string.url_path_catalog);
        setStringToSharedPreferences(getString(R.string.preference_key_value_catalog_store), catalogStore);
    }

    if (StringUtils.isBlank(catalogId)) {
        catalogId = getString(R.string.url_path_catalog_id);
        setStringToSharedPreferences(getString(R.string.preference_key_value_catalog_id), catalogId);
    }

    if (StringUtils.isBlank(catalogMainCategory)) {
        catalogMainCategory = getString(R.string.id_category_main);
        setStringToSharedPreferences(getString(R.string.preference_key_value_catalog_main_category_id),
                catalogMainCategory);
    }

    // Updating the pre-defined catalog key
    String catalogKey = catalogStore + "|" + catalogId + "|" + catalogMainCategory;
    int index = ArrayUtils.indexOf(getResources().getStringArray(R.array.backend_catalog_values), catalogKey);
    setStringToSharedPreferences(getString(R.string.preference_key_key_catalog),
            getResources().getStringArray(R.array.backend_catalog_keys)[index]);

    // Configuration for the backend url
    com.hybris.mobile.lib.commerce.Configuration configuration = new com.hybris.mobile.lib.commerce.Configuration();
    configuration.setBackendUrl(urlBackend);
    configuration.setCatalogId(catalogId);
    configuration.setCatalog(catalogStore);
    configuration.setCatalogVersionId(mInstance.getString(R.string.url_path_catalog_version_id));
    configuration.setCatalogAuthority(getString(R.string.provider_authority));
    configuration.setCatalogIdMainCategory(catalogMainCategory);

    // Bypassing SSLHelperSyncService
    TrustManager[] trustManager = new TrustManager[] { new X509TrustManager() {
        @Override
        public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
        }

        @Override
        public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
        }

        @Override
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    } };

    SSLContext sslContext = null;

    try {
        sslContext = SSLContext.getInstance("SSL");
        sslContext.init(null, trustManager, new java.security.SecureRandom());
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        Log.e(TAG, "Error with SSLHelperSyncService. Details: " + e.getLocalizedMessage());
    }

    if (sslContext == null) {
        throw new IllegalStateException("Unable to get an instance of SSLContext");
    }

    // Creating the content service helper
    mInstance.mContentServiceHelper = buildContentServiceHelper(configuration, sslContext.getSocketFactory(),
            new HostnameVerifier() {
                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            });

    // Build the configuration for the app
    mConfiguration = Configuration.buildConfiguration(this);

    // Barcode scanner instance
    mScannerHelper = new ScannerHelper(new CommerceBarcodeCheckerFactory());

    // Register local broadcast to Logout
    LocalBroadcastManager.getInstance(this).registerReceiver(new LogoutBroadcastReceiver(),
            new IntentFilter(getString(R.string.intent_action_logout)));

    // Register local broadcast to update cache on the content service helper
    LocalBroadcastManager.getInstance(this).registerReceiver(new UpdateCacheBroadcastReceiver(),
            new IntentFilter(getString(R.string.intent_action_update_cache)));

    // Default account for the sync adapter
    addCatalogSyncAdapterDefaultAccount();

    // We sync in advance the main category of the catalog to create the sync adapter and accelerate the process
    Bundle bundle = new Bundle();
    bundle.putString(CatalogSyncConstants.SYNC_PARAM_GROUP_ID, catalogMainCategory);
    bundle.putInt(CatalogSyncConstants.SYNC_PARAM_CURRENT_PAGE, 0);
    bundle.putInt(CatalogSyncConstants.SYNC_PARAM_PAGE_SIZE, mConfiguration.getDefaultPageSize());
    requestCatalogSyncAdapter(bundle);
}

From source file:com.iss.android.wearable.datalayer.MainActivity.java

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

    // restart of the dataservice retrieving data from the sensor

    if (SensorsDataService.itself == null) {
        Intent intent = new Intent(this, SensorsDataService.class);
        startService(intent);//w  w  w.j ava 2s . c om
    }

    //mGoogleApiClient.connect();
    if (dataUpdateReceiver == null)
        dataUpdateReceiver = new DataUpdateReceiver();
    IntentFilter intentFilter = new IntentFilter(SensorsDataService.NEW_MESSAGE_AVAILABLE);
    registerReceiver(dataUpdateReceiver, intentFilter);

    /*if (SensorsDataService.itself != null){
    SensorsDataService.itself.StopSleepTracking();
    }*/

    RegisterBroadcastsReceiver();

    showCurrentAppState();

}

From source file:com.snt.bt.recon.activities.MainActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(com.snt.bt.recon.R.layout.activity_main);
    ButterKnife.bind(this);
    logDebug("Activity", "######################## On Create ########################");
    //Lock orientation
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    //Leave screen on
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    //leave cpu on
    wl = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "wlTag");
    wl.acquire();//www  .  j a  v  a  2 s  .  c  o  m

    //For device id
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    //for connectivity
    cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    try {

        logDebug("DatabaseTest", "Reading all trips..");
        List<Trip> trips = db.getAll(Trip.class);
        for (Trip trip : trips) {
            String log = "session id: " + trip.getSessionId() + " imei: " + trip.getImei() + " transport: "
                    + trip.getTransport() + " TS: " + trip.getTimestampStart() + " TE: "
                    + trip.getTimestampEnd() + " upload status: " + trip.getUploadStatus();
            logDebug("DatabaseTest", log);
        }
        logDebug("DatabaseTest", "Reading all locations..");
        List<GPSLocation> locs = db.getAll(GPSLocation.class);
        for (GPSLocation loc : locs) {
            String log = "loc id: " + loc.getLocationId() + " sess id: " + loc.getSessionId() + " timestamp: "
                    + loc.getTimestamp() + " upload status: " + loc.getUploadStatus();
            logDebug("DatabaseTest", log);
        }
        logDebug("DatabaseTest", "Reading all bc..");
        List<BluetoothClassicEntry> bcs = db.getAll(BluetoothClassicEntry.class);
        for (BluetoothClassicEntry bc : bcs) {
            String log = "sess id: " + bc.getSessionId() + " loc id: " + bc.getLocationId() + " upload status: "
                    + bc.getUploadStatus();
            logDebug("DatabaseTest", log);
        }
        logDebug("DatabaseTest", "Reading all ble..");
        List<BluetoothLowEnergyEntry> bles = db.getAll(BluetoothLowEnergyEntry.class);
        for (BluetoothLowEnergyEntry ble : bles) {
            String log = "sess id: " + ble.getSessionId() + " loc id: " + ble.getLocationId()
                    + " upload status: " + ble.getUploadStatus();
            logDebug("DatabaseTest", log);
        }
    } catch (InstantiationException | IllegalAccessException e) {
        e.printStackTrace();
    }

    //Show select transpot mode
    new TransportMode(this).show();

    // Show EULA
    new AppEULA(this).show();

    //displayFeedbackDialog();

    //avtivity recognition start
    mActivityRecognitionScan = new ActivityRecognitionUtil(this);
    mActivityRecognitionScan.startActivityRecognitionScan();
    //Filter the Intent and register broadcast receiver
    registerReceiver(ActivityRecognitionReceiver, new IntentFilter("ImActive"));

    //gps
    gpsStatusCheck();

    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    locationListener = new MyLocationListener();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 3, locationListener);

    //bt
    mBluetoothUtils = new BluetoothUtils(this);

    //ble
    mLeDeviceStore = new BluetoothLeDeviceStore();
    mLeScanner = new BluetoothLeScanner(mLeScanCallback, mBluetoothUtils);
    //bc
    mBcDeviceList = new ArrayList<>();

    final Handler h = new Handler();
    final int delay = 60000;

    h.postDelayed(new Runnable() {
        public void run() {
            syncServerDatabase();

            h.postDelayed(this, delay);
        }
    }, delay);

    //Clean BLE table in case device last timestamp is > 10 seconds
    final Handler h2 = new Handler();
    h2.postDelayed(new Runnable() {
        public void run() {
            //clear old ble devices
            for (BluetoothLeDevice device : mLeDeviceStore.getDeviceList()) {
                long diff = System.currentTimeMillis() - device.getTimestamp();
                if (diff > 10000) {
                    mLeDeviceStore.removeDevice(device);
                    //Refresh the listview
                    final EasyObjectCursor<BluetoothLeDevice> c = mLeDeviceStore.getDeviceCursor();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mLeDeviceListAdapter.swapCursor(c);
                        }
                    });
                }
            }

            h2.postDelayed(this, 1000);//1 sec
        }
    }, 1000);
}

From source file:com.google.codelabs.appauth.MainActivity.java

private void registerRestrictionsReceiver() {
    IntentFilter restrictionsFilter = new IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED);

    mRestrictionsReceiver = new BroadcastReceiver() {
        @Override//from  w  ww  . ja  v a 2  s .  c om
        public void onReceive(Context context, Intent intent) {
            getAppRestrictions();
        }
    };

    registerReceiver(mRestrictionsReceiver, restrictionsFilter);
}

From source file:com.dileepindia.cordova.sms.SMSPlugin.java

protected void createIncomingSMSReceiver() {
    Context ctx = this.cordova.getActivity();

    this.mReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Log.d("SMSPlugin", "onRecieve: " + action);

            if ("android.provider.Telephony.SMS_RECEIVED".equals(action)) {
                if (SMSPlugin.this.mIntercept) {
                    abortBroadcast();// w  ww  .  java2s .c  o m
                }
                Bundle bundle = intent.getExtras();
                if (bundle != null) {
                    Object[] pdus = (Object[]) bundle.get("pdus");
                    if (pdus.length != 0) {
                        for (int i = 0; i < pdus.length; i++) {
                            SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdus[i]);

                            JSONObject json = SMSPlugin.this.getJsonFromSmsMessage(sms);
                            SMSPlugin.this.onSMSArrive(json);
                        }

                    }
                }
            }
        }
    };
    String[] filterstr = { "android.provider.Telephony.SMS_RECEIVED" };
    for (int i = 0; i < filterstr.length; i++) {
        IntentFilter filter = new IntentFilter(filterstr[i]);
        filter.setPriority(100);
        ctx.registerReceiver(this.mReceiver, filter);
        Log.d("SMSPlugin", "broadcast receiver registered for: " + filterstr[i]);
    }
}

From source file:com.dwdesign.tweetings.fragment.AccountsFragment.java

@Override
public void onStart() {
    super.onStart();
    final IntentFilter filter = new IntentFilter(BROADCAST_ACCOUNT_LIST_DATABASE_UPDATED);
    registerReceiver(mStatusReceiver, filter);
    if (!mActivityFirstCreated) {
        getLoaderManager().restartLoader(0, null, this);
    }//from  w w w  .ja v  a  2s  .c o  m
}