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() 

Source Link

Document

New empty IntentFilter.

Usage

From source file:Main.java

public static int getBatteryLevel(Context context) {

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_BATTERY_CHANGED);
    Intent intent = context.registerReceiver(null, filter);
    if (intent == null) {
        return -1;
    }/*from  ww  w. j av  a 2 s . c  o  m*/
    return intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
}

From source file:Main.java

public static void registerReceiver(Context context, BroadcastReceiver receiver, String action) {
    IntentFilter filter = new IntentFilter();
    filter.addAction(action);//from ww  w.  j ava  2  s  .  co m
    context.registerReceiver(receiver, filter);
}

From source file:Main.java

public static void registBroadcase(Activity activity, BroadcastReceiver receiver, String name) {
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(activity);
    IntentFilter filter = new IntentFilter();
    filter.addAction(name);// w  w  w  .j  a va2  s  . c  o m
    broadcastManager.registerReceiver(receiver, filter);
}

From source file:Main.java

/**
 * register bluetooth receiver/*from  w  ww . jav  a 2s .  c  o m*/
 *
 * @param receiver bluetooth broadcast receiver
 * @param activity activity
 */
public static void registerBluetoothReceiver(BroadcastReceiver receiver, Activity activity) {
    if (null == receiver || null == activity) {
        return;
    }
    IntentFilter intentFilter = new IntentFilter();
    //start discovery
    intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    //finish discovery
    intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    //bluetooth status change
    intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    //found device
    intentFilter.addAction(BluetoothDevice.ACTION_FOUND);
    //bond status change
    intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
    //pairing device
    intentFilter.addAction("android.bluetooth.device.action.PAIRING_REQUEST");
    activity.registerReceiver(receiver, intentFilter);
}

From source file:Main.java

public static void registerBroadcast(Context context, String action, BroadcastReceiver broadcastReceiver) {
    if (context == null || TextUtils.isEmpty(action) || broadcastReceiver == null) {
        return;//w  w  w.  j av  a2  s.c  om
    }
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(action);
    context.registerReceiver(broadcastReceiver, intentFilter);
}

From source file:edu.cmu.plugins.PhoneListener.java

/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 * //w  ww . j ava2  s.c  om
 * @param ctx The context of the main Activity.
 */
public void setContext(PhonegapActivity ctx) {
    super.setContext(ctx);
    this.phoneListenerCallbackId = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");

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

            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent == null) {
                    return;
                }
                String state = "";
                if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
                    state = "SMS_RECEIVED";
                    Log.i(LOG_TAG, state);
                }
                if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;

                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                }
                updatePhoneState(state, true);
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        ctx.registerReceiver(this.receiver, intentFilter);
    }
}

From source file:com.example.plugin.PhoneListener.java

public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    this.phoneListenerCallbackId = null;
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override//ww  w.  j  a v a 2 s .c om
            public void onReceive(Context context, Intent intent) {
                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;
                    String state;
                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                    updatePhoneState(state, true);
                }
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        cordova.getActivity().registerReceiver(this.receiver, intentFilter);
        this.registered = true;
    }

}

From source file:com.toppatch.mv.ui.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    String TAG = "MainActivity.onCreate";
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent intent = getIntent();//from   www.  ja  v a 2 s.  c  o  m
    intent.getExtras();
    Boolean bool = intent.getBooleanExtra("fromReciever", false);
    IntentFilter filter = new IntentFilter();
    filter.addAction(EnterpriseLicenseManager.ACTION_LICENSE_STATUS);
    samsungReciever = new SamsungReceiver();
    this.registerReceiver(samsungReciever, filter);
    if (bool == true) {
        acceptConditions = (Button) findViewById(R.id.acceptConditionsButton);
        acceptConditions.setText("Sorry you need to accept conditions to proceed....");
        acceptConditions.setClickable(true);
    } else {
        Log.i("see", "oncreate");
        checkConditions();
    }

}

From source file:com.ripperdesignandmultimedia.phoneblockplugin.PhoneBlockerPlugin.java

/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 * //www . ja v a2  s.c o m
 * @param ctx The context of the main Activity.
 */
public void setContext(CordovaInterface ctx) {
    super.setContext(ctx);
    this.phoneBlockerCallbackId = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;
                    String state;
                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                    updatePhoneState(state, true);
                }
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        cordova.getActivity().registerReceiver(this.receiver, intentFilter);
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.presence.MusicPresence.java

@Override
public void onPresenceUpdated(final Context context, final Uri feedUri, boolean present) {
    if (mShareMusic) {
        if (getFeedsWithPresence().size() == 0) {
            context.getApplicationContext().unregisterReceiver(mReceiver);
            Toast.makeText(context, "No longer sharing music", Toast.LENGTH_SHORT).show();
            mShareMusic = false;/*ww  w .ja  v a  2s  . co  m*/
        }
    } else {
        if (getFeedsWithPresence().size() > 0) {
            IntentFilter iF = new IntentFilter();
            iF.addAction("com.android.music.metachanged");
            context.getApplicationContext().registerReceiver(mReceiver, iF);
            Toast.makeText(context, "Now sharing music", Toast.LENGTH_SHORT).show();
            mShareMusic = true;
        }
    }
}