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.licpro.filebox.activities.LoginActivity.java

@Override
protected void onResume() {
    super.onResume();
    Log.i(LOGCAT_TAG, "LoginActivity::onResume()");

    /* Register the broadcast receiver for the service callback */
    registerReceiver(mAuthTokenBroadcastReceiver, new IntentFilter(ConnectionSync.ACTION_CONNECTION_SUCCESS));
    registerReceiver(mAuthTokenBroadcastReceiver, new IntentFilter(ConnectionSync.ACTION_CONNECTION_ERROR));
}

From source file:com.wso2.mobile.mdm.api.PhoneState.java

/**
*Returns the device battery information//from www .ja  v a 2s  .  c om
*/
public float getBatteryLevel() {
    Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

    // Error checking that probably isn't needed but I added just in case.
    if (level == -1 || scale == -1) {
        return 50.0f;
    }

    return ((float) level / (float) scale) * 100.0f;
    /*BroadcastReceiver batteryReceiver = new BroadcastReceiver() {
    int scale = -1;
    int level = -1;
    int voltage = -1;
    int temp = -1;
    @Override
    public void onReceive(Context context, Intent intent) {
        level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
        scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
        temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
        voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
        Log.v("Battery Level", "level is "+level+"/"+scale+", temp is "+temp+", voltage is "+voltage);
                
        Battery battery = Battery.getInstance();
        battery.setLevel(level);
        battery.setScale(scale);
        battery.setTemp(temp);
        battery.setVoltage(voltage);
                
    }
      };
      IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
      context.registerReceiver(batteryReceiver, filter);
    return Battery.getInstance();*/
}

From source file:com.amaze.carbonfilemanager.services.ExtractService.java

@Override
public void onCreate() {
    registerReceiver(receiver1, new IntentFilter(TAG_BROADCAST_EXTRACT_CANCEL));
    cd = getApplicationContext();
}

From source file:com.polyvi.xface.extension.telephony.XTelephonyExt.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    mContext = cordova.getActivity();//from   ww w. j  a v a  2 s  .  co m
    mContentResolver = cordova.getActivity().getContentResolver();
    genIncomingCallBroadcastReceiver();
    cordova.getActivity().registerReceiver(mIncomingCallBroadcastReceiver,
            new IntentFilter(ACTION_PHONE_STATE_CHANGED));
}

From source file:com.googlecode.android_scripting.facade.USBHostSerialFacade.java

/**
 * registerIntent: from usbserialConnect {{{1
 *///w ww  . ja v  a2 s .co m
private void registerIntent() {
    if (mReceiver != null) {
        // this function was already called.
        return;
    }

    Log.d("Register USB Intents...");
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    mReceiver = new USBHostSerialReceiver();
    mService.registerReceiver(mReceiver, filter);
}

From source file:edu.uri.egr.hermes.manipulators.FileLog.java

public String battery() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent batteryStatus = Hermes.get().getContext().registerReceiver(null, filter);

    return String.valueOf(batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL,
            -1 / batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1) * 100));
}

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

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

    setToolbar();//from   w w  w .jav a  2  s .c  om
    initUI(); //maps xml interface with java

    recyclerViewDevelop(); //setting recycleview
    swipeToRefresh(); // setup swipe to refresh
    checkConnection(); //check connection with internet

    filters = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);

}

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

@Override
protected void initListener() {
    super.initListener();
    IntentFilter callFilter = new IntentFilter(EMChatManager.getInstance().getIncomingCallBroadcastAction());
    if (callReceiver == null) {
        callReceiver = new CallReceiver();
    }/*  w  w w.  ja  v a  2  s  .c o  m*/

    // ?
    appContext.registerReceiver(callReceiver, callFilter);
    // ??
    initEventListener();
}

From source file:com.nfc.gemkey.MainActivity.java

@Override
public void onCreate(Bundle icicle) {
    if (DEBUG)/*w ww  . jav  a 2s .co m*/
        Log.d(TAG, "onCreate");
    super.onCreate(icicle);
    setContentView(R.layout.activity_main);

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
    // will fill in the intent with the details of the discovered tag before delivering to
    // this activity.
    mPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Setup an intent filter for all MIME based dispatches
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    tagDetected.addCategory(Intent.CATEGORY_DEFAULT);
    mFilters = new IntentFilter[] { tagDetected };

    mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);

    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
    registerReceiver(mUsbReceiver, filter);

    if (getLastNonConfigurationInstance() != null) {
        Log.i(TAG, "open usb accessory@onCreate");
        mAccessory = (UsbAccessory) getLastNonConfigurationInstance();
        openAccessory(mAccessory);
    }

    buttonLED = (ToggleButton) findViewById(R.id.nfc_btn);
    buttonLED.setBackgroundResource(
            buttonLED.isChecked() ? R.drawable.btn_toggle_yes : R.drawable.btn_toggle_no);
    buttonLED.setOnCheckedChangeListener(mKeyLockListener);

    tagId = (TextView) findViewById(R.id.nfc_tag);
    tagId.setText(R.string.nfc_scan_tag);

    // Avoid NetworkOnMainThreadException
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());

    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());

    setVolumeControlStream(AudioManager.STREAM_MUSIC);
}

From source file:com.mobicage.rogerthat.registration.OauthRegistrationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    T.UI();//from  w  w w .  j av  a  2 s  .c  o m
    init(this);
    mHttpClient = HTTPUtil.getHttpClient(HTTP_TIMEOUT, HTTP_RETRY_COUNT);

    final IntentFilter filter = new IntentFilter(INTENT_LOG_URL);
    registerReceiver(mBroadcastReceiver, filter);

    // TODO: This has to be improved.
    // If the app relies on GCM the user should not be able to register.
    if (CloudConstants.USE_GCM_KICK_CHANNEL)
        GoogleServicesUtils.checkPlayServices(this);
}