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.app.jdy.ui.CashAdvanceActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cashadvance);
    initView();/*from   w w  w  .j  a  v  a2 s.  c  om*/

    // ????
    btnConfirmReceiver = new BtnConfirmReceiver();
    IntentFilter intentFilter = new IntentFilter("org.jdy.action.WITHDCASH_BROADCAST");
    CashAdvanceActivity.this.registerReceiver(btnConfirmReceiver, intentFilter);

    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
            // ?????
            case 1:
                Bundle bundle = msg.getData();

                canWithdCash = bundle.getString("canWithdCash");
                String bankName = bundle.getString("bankName");
                bankCode1 = bundle.getString("bankCode1");
                String bankCode = bundle.getString("bankCode");

                if (StringUtils.isNullOrEmpty(bankName)) {
                    bankName = "?";
                }
                // ?
                textView4.setText(bankName);

                // ?
                textView3.setText("(" + bankCode + ")");
                if (StringUtils.isNullOrEmpty(bankCode)) {
                    textView3.setText("");
                }

                // ??????
                textView2.setText(canWithdCash);

                // ?????
                editText.setText(canWithdCash);

                break;

            // ?????
            case 2:
                if (withdrawCashDialog != null) {
                    withdrawCashDialog.dismiss();
                }
                break;

            // ???????
            case 3:
                Toast.makeText(CashAdvanceActivity.this,
                        "??? " + withdrawresult + " ???", Toast.LENGTH_LONG)
                        .show();

                editText.setText("");
                if (withdrawCashDialog != null) {
                    withdrawCashDialog.dismiss();
                }
                finish();

                break;

            // ??????
            case 0x110:
                Toast.makeText(CashAdvanceActivity.this, "??", Toast.LENGTH_SHORT).show();

                if (withdrawCashDialog != null) {
                    withdrawCashDialog.dismiss();
                }
                break;

            // ????????????
            case 4:
                Toast.makeText(CashAdvanceActivity.this, Constants.NO_INTENT_TIPS, Toast.LENGTH_LONG).show();
                if (withdrawCashDialog != null) {
                    withdrawCashDialog.dismiss();
                }
                break;
            default:
                break;
            }

        }
    };
    addEvents();
}

From source file:com.fastbootmobile.twofactorauthdemo.MainActivity.java

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

    setContentView(R.layout.info_layout);

    Button regButton = (Button) findViewById(R.id.register);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        if (extras.getString("otp", null) != null) {
            TextView txt = (TextView) findViewById(R.id.txt);
            regButton.setVisibility(View.GONE);
            txt.setText("One Time Password :  " + extras.getString("otp", null));
            return;
        }//from w  w w.j  a  v  a  2 s  . com
    }

    mReg = new OwnPushRegistrant(this);
    mHandler = new Handler();
    receiver = new RegisterReceiver(new Handler());

    IntentFilter filter = new IntentFilter(OwnPushClient.INTENT_REGISTER);
    filter.addCategory(BuildConfig.APP_PUBLIC_KEY);

    registerReceiver(receiver, filter);

    final SharedPreferences prefs = this.getApplicationContext().getSharedPreferences(OwnPushClient.PREF_PUSH,
            Context.MODE_PRIVATE);

    if (!prefs.getBoolean(OwnPushClient.PREF_REG_DONE, false)) {

        regButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OwnPushCrypto fp = new OwnPushCrypto();
                OwnPushCrypto.AppKeyPair keys = fp.generateInstallKey();

                boolean ret = mReg.register(BuildConfig.APP_PUBLIC_KEY, keys.getPublicKey());

                if (ret) {
                    //STORE THEM
                    prefs.edit().putString(OwnPushClient.PREF_PUBLIC_KEY, keys.getPublicKey()).commit();
                    prefs.edit().putString(OwnPushClient.PREF_PRIVATE_KEY, keys.getPrivateKey()).commit();
                }
            }
        });
    } else {
        regButton.setVisibility(View.GONE);

        updateUI();

        if (prefs.getString("device_uid", null) == null) {
            registerWithBackend();
        }
    }

}

From source file:com.spondbob.bluetooth.BluetoothActivity.java

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

    // Setup the window
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.device_list);

    // Set result CANCELED in case the user backs out
    setResult(Activity.RESULT_CANCELED);

    // Initialize array adapters. One for already paired devices and
    // one for newly discovered devices
    mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);

    // Find and set up the ListView for newly discovered devices
    newDevicesListView = (ListView) findViewById(R.id.new_devices);
    newDevicesListView.setAdapter(mNewDevicesArrayAdapter);

    // Register for broadcasts when a device is discovered
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    this.registerReceiver(mReceiver, filter);

    // Register for broadcasts when discovery has finished
    filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    this.registerReceiver(mReceiver, filter);

    // Get the local Bluetooth adapter
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
}

From source file:foam.starwisp.NetworkManager.java

void Start(String ssid, StarwispActivity c, String name, StarwispBuilder b) {
    Log.i("starwisp", "Network startup!");
    m_CallbackName = name;//w  ww .j a  v a 2  s  . com
    m_Context = c;
    m_Builder = b;

    if (state == NetworkManager.State.IDLE) {
        Log.i("starwisp", "State is idle, launching scan");

        wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
        state = State.SCANNING;
        SSID = ssid;
        wifi.startScan();
        receiver = new WiFiScanReceiver(SSID, this);
        c.registerReceiver(receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));

        // todo - won't work from inside fragments
        m_Builder.DialogCallback(m_Context, m_Context.m_Name, m_CallbackName, "\"Scanning\"");
    }

    if (state == NetworkManager.State.CONNECTED) {
        Log.i("starwisp", "State is connected, callback raised");
        m_Builder.DialogCallback(m_Context, m_Context.m_Name, m_CallbackName, "\"Connected\"");
    }
}

From source file:it.gmariotti.android.apps.dashclock.extensions.battery.BatteryExtension.java

@Override
protected void onInitialize(boolean isReconnect) {
    super.onInitialize(isReconnect);

    readPreferences();//from w  w w. j  a  v a  2  s  . c o m

    if (onClickReceiver != null) {
        try {
            unregisterReceiver(onClickReceiver);
        } catch (Exception e) {
        }
    }

    IntentFilter intentFilter = new IntentFilter(REFRESH_INTENT_FILTER);
    onClickReceiver = new OnClickReceiver();
    registerReceiver(onClickReceiver, intentFilter);

    IntentFilter filterScreen = new IntentFilter();
    filterScreen.addAction(Intent.ACTION_SCREEN_ON);

    getApplicationContext().registerReceiver(mScreenOnReceiver, filterScreen);

    //scheduleRefresh(0);
}

From source file:com.szanata.cordova.phonestatechangelistener.PhoneStateChangeListener.java

/**
 * creates a new BroadcastReceiver to listen whether the Telephony State changes
 *//*from  w ww . j av  a 2s . c om*/
public void startPhoneListener(final CallbackContext callbackContext) {

    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(final Context context, final Intent intent) {

                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    String state = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : NONE;
                    String number = "";

                    if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
                    }

                    final JSONObject data = new JSONObject();
                    try {
                        data.put("state", state);
                        data.put("number", number);
                        callbackContext.success(data);
                    } catch (final JSONException e) {
                        callbackContext.error(e.getMessage());
                    }

                }
            }
        };

        this.context.registerReceiver(this.receiver,
                new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED));
    }
}

From source file:fr.inria.ucn.collectors.SysStateCollector.java

/**
 * /*from  w  ww.  ja va2  s .  c  om*/
 * @param c
 * @param ts
 * @param change
 */
@SuppressLint("NewApi")
public void run(Context c, long ts, boolean change) {
    try {
        JSONObject data = new JSONObject();
        data.put("on_screen_state_change", change); // this collection run was triggered by screen state change

        data.put("hostname", Helpers.getSystemProperty("net.hostname", "unknown hostname"));
        data.put("current_timezone", Time.getCurrentTimezone());

        // general memory state
        ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
        MemoryInfo mi = new MemoryInfo();
        am.getMemoryInfo(mi);

        JSONObject mem = new JSONObject();
        mem.put("available", mi.availMem);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
            mem.put("total", mi.totalMem);
        }
        mem.put("is_low", mi.lowMemory);
        data.put("memory", mem);

        // screen state
        PowerManager pm = (PowerManager) c.getSystemService(Context.POWER_SERVICE);
        data.put("screen_on", pm.isScreenOn());

        // battery state
        IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        Intent battery = c.registerReceiver(null, ifilter);
        int level = battery.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
        int scale = battery.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
        float pct = (float) (100.0 * level) / scale;
        int status = battery.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
        boolean isCharging = (status == BatteryManager.BATTERY_STATUS_CHARGING
                || status == BatteryManager.BATTERY_STATUS_FULL);
        int chargePlug = battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
        boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;

        JSONObject batt = new JSONObject();
        batt.put("level", level);
        batt.put("scale", scale);
        batt.put("pct", pct);
        batt.put("is_charging", isCharging);
        batt.put("usb_charge", usbCharge);
        batt.put("ac_charge", acCharge);
        data.put("battery", batt);

        // some proc stats
        data.put("cpu", getCpuStat());
        data.put("loadavg", getLoadStat());
        data.put("uptime", getUptimeStat());

        // audio state
        data.put("audio", getAudioState(c));

        // done
        Helpers.sendResultObj(c, "system_state", ts, data);

    } catch (JSONException jex) {
        Log.w(Constants.LOGTAG, "failed to create json object", jex);
    }
}

From source file:com.szanata.cordova.plugins.PhoneStateChangeListener.java

/**
 * creates a new BroadcastReceiver to listen whether the Telephony State changes
 *//*w w  w  .ja v  a2  s  .c o  m*/
public void startPhoneListener() {

    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(final Context context, final Intent intent) {

                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    String state = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : NONE;
                    String number = "";

                    if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
                    }
                    if (callbackContext != null) {
                        final JSONObject data = new JSONObject();
                        try {
                            data.put("state", state);
                            data.put("number", number);
                        } catch (final JSONException e) {
                        }
                        ;
                        callbackContext.success(data);
                    }
                }
            }
        };

        this.context.registerReceiver(this.receiver,
                new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED));
    }
}

From source file:com.sftoolworks.nfcoptions.SelectActivity.java

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

    if (!handledIntent) {
        if (getIntent().getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) {
            if (!launchIntent) {

                Log.d(TAG, "This is a second tap");
                writeSelection(getIntent());

            }//from   www .jav  a 2  s  .  c om
        }
        handledIntent = true;
    }

    nfcAdapter.enableForegroundDispatch(this, pendingIntent,
            new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED) }, null);

}

From source file:com.myandroidremote.AccountsActivity.java

/**
 * Begins the activity./*from   w ww .j  a  v  a2 s  . c om*/
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Register a receiver to provide register/unregister notifications
    registerReceiver(mUpdateUIReceiver, new IntentFilter(Util.UPDATE_UI_INTENT));

    SharedPreferences prefs = Util.getSharedPreferences(mContext);
    String deviceRegistrationID = prefs.getString(Util.DEVICE_REGISTRATION_ID, null);
    if (deviceRegistrationID == null) {
        // Show the 'connect' screen if we are not connected
        setScreenContent(R.layout.connect);
    } else {
        // Show the 'disconnect' screen if we are connected
        setScreenContent(R.layout.disconnect);
    }
}