List of usage examples for android.content IntentFilter addAction
public final void addAction(String action)
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. * //from w w w . ja v a 2s . 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:alexander.martinz.sample.webserver.MainActivity.java
private void registerReceivers() { final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("android.net.wifi.WIFI_STATE_CHANGED"); intentFilter.addAction("android.net.wifi.STATE_CHANGE"); registerReceiver(broadcastReceiver, intentFilter); }
From source file:com.givon.anhao.BaseActivity.java
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); requestWindowFeature(Window.FEATURE_NO_TITLE); if (mBroadcastReceiver == null) { mBroadcastReceiver = new BroadcastReceiver() { @Override// w w w. ja v a2s . c o m public void onReceive(Context context, Intent intent) { finish(); } }; IntentFilter filter = new IntentFilter(); filter.addAction(getApplicationContext().getPackageName() + Constant.ACTION_EXIT_SYSTEM); this.registerReceiver(mBroadcastReceiver, filter); } initLayoutView(); }
From source file:com.hrs.filltheform.service.MyAccessibilityService.java
@Override protected void onServiceConnected() { super.onServiceConnected(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(INTENT_ASK_FOR_LOADED_PACKAGE_NAMES); addCompanionActions(intentFilter);// www .ja va 2 s .c o m registerReceiver(broadcastReceiver, intentFilter); setUpServiceConfiguration(); }
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 w w . j a v a2 s . com * @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:answer.example.answer.activity.FileChooserActivity.java
/** * Register the external storage BroadcastReceiver. *///from w ww. java2 s.co m private void registerStorageListener() { IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_MEDIA_REMOVED); registerReceiver(mStorageListener, filter); }
From source file:com.cyanogenmod.settings.otgtoggle.UsbDeviceMonitorService.java
@Override public void onCreate() { super.onCreate(); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mUsbManager = (UsbManager) getSystemService(USB_SERVICE); mStateMachine = new UsbPortStateMachine(this); mStateMachine.setDbg(true); // XXX mStateMachine.start();//from www. jav a 2 s . co m IntentFilter filter = new IntentFilter(); filter.addAction(AudioManager.ACTION_HEADSET_PLUG); filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); registerReceiver(mDeviceStateReceiver, filter); }
From source file:android.net.http.cts.ApacheHttpClientTest.java
private void connectToWifi() throws InterruptedException { if (!mWifiManager.isWifiEnabled()) { ConnectivityActionReceiver receiver = new ConnectivityActionReceiver(ConnectivityManager.TYPE_WIFI, State.CONNECTED); IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); mContext.registerReceiver(receiver, filter); assertTrue(mWifiManager.setWifiEnabled(true)); assertTrue("Wifi must be configured to connect to an access point for this test.", receiver.waitForStateChange()); mContext.unregisterReceiver(receiver); }/*from w ww . j a va2 s. c o m*/ }
From source file:com.dwdesign.tweetings.fragment.SearchTweetsFragment.java
@Override public void onResume() { super.onResume(); IntentFilter filter = new IntentFilter(); filter.addAction(BROADCAST_VOLUME_UP); filter.addAction(BROADCAST_VOLUME_DOWN); registerReceiver(receiver, filter);/*from ww w .j a v a2 s.com*/ }
From source file:com.android.trustagent.test.SampleTrustAgent.java
@Override public void onCreate() { super.onCreate(); mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_GRANT_TRUST); filter.addAction(ACTION_REVOKE_TRUST); mLocalBroadcastManager.registerReceiver(mReceiver, filter); if (ALLOW_EXTERNAL_BROADCASTS) { registerReceiver(mReceiver, filter); }//ww w. j a v a2 s . c om setManagingTrust(getIsManagingTrust(this)); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); }