List of usage examples for android.content IntentFilter IntentFilter
public IntentFilter()
From source file:com.polyvi.xface.extension.XBatteryExt.java
@Override public XExtensionResult exec(String action, JSONArray args, XCallbackContext callbackCtx) throws JSONException { XExtensionResult.Status status = XExtensionResult.Status.INVALID_ACTION; String result = "Unsupported Operation: " + action; if (COMMAND_START.equals(action)) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); final XCallbackContext cbCtx = callbackCtx; if (null == mBroadcastReceiver) { mBroadcastReceiver = new BroadcastReceiver() { @Override/*from w w w . j ava 2s . co m*/ public void onReceive(Context context, Intent intent) { XLog.d(CLASS_NAME, "received broadcast of battery changing"); updateBatteryInfo(intent, cbCtx); } }; getContext().registerReceiver(mBroadcastReceiver, intentFilter); } XExtensionResult extensionResult = new XExtensionResult(XExtensionResult.Status.NO_RESULT); extensionResult.setKeepCallback(true); return extensionResult; } else if (COMMAND_STOP.equals(action)) { removeBatteryListener(); sendUpdate(new JSONObject(), callbackCtx, false); return new XExtensionResult(XExtensionResult.Status.OK); } return new XExtensionResult(status, result); }
From source file:net.atlaslearning.cordova.OpenIn.OpenIn.java
/** * Executes the request./* w w w . j a v a 2 s.c om*/ * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @return True if the action was valid, false if not. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("start")) { if (this.batteryCallbackContext != null) { callbackContext.error("Battery listener already running."); return true; } this.batteryCallbackContext = callbackContext; // We need to listen to power events to update battery status IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateBatteryInfo(intent); } }; cordova.getActivity().registerReceiver(this.receiver, intentFilter); } // Don't return any result now, since status results will be sent when events come in from broadcast receiver PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); return true; } else if (action.equals("stop")) { removeBatteryListener(); this.sendUpdate(new JSONObject(), false); // release status callback in JS side this.batteryCallbackContext = null; callbackContext.success(); return true; } return false; }
From source file:com.phonegap.BatteryListener.java
/** * Executes the request and returns PluginResult. * /*from w w w. ja va2s. c om*/ * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. */ public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.INVALID_ACTION; String result = "Unsupported Operation: " + action; if (action.equals("start")) { if (this.batteryCallbackId != null) { return new PluginResult(PluginResult.Status.ERROR, "Battery listener already running."); } this.batteryCallbackId = callbackId; // We need to listen to power events to update battery status IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateBatteryInfo(intent); } }; ctx.registerReceiver(this.receiver, intentFilter); } // Don't return any result now, since status results will be sent when events come in from broadcast receiver PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); return pluginResult; } else if (action.equals("stop")) { removeBatteryListener(); this.sendUpdate(new JSONObject(), false); // release status callback in JS side this.batteryCallbackId = null; return new PluginResult(PluginResult.Status.OK); } return new PluginResult(status, result); }
From source file:com.remobile.batteryStatus.BatteryListener.java
/** * Executes the request./* w w w. j a va 2 s . c o m*/ * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @return True if the action was valid, false if not. */ @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("start")) { // We need to listen to power events to update battery status IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateBatteryInfo(intent); } }; getReactApplicationContext().registerReceiver(this.receiver, intentFilter); } // Don't return any result now, since status results will be sent when events come in from broadcast receiver callbackContext.success(); return true; } else if (action.equals("stop")) { removeBatteryListener(); callbackContext.success(); return true; } return false; }
From source file:com.github.opengarageapp.activity.MainActivity.java
@Override protected void onResume() { super.onResume(); IntentFilter filter = new IntentFilter(); filter.addAction(GarageToggleService.INTENT_CLOSE1); filter.addAction(GarageToggleService.INTENT_TOGGLE1); filter.addAction(GarageToggleService.INTENT_ERROR); filter.addAction(GarageToggleService.INTENT_STATE1); filter.addAction(GarageToggleService.INTENT_CLOSE2); filter.addAction(GarageToggleService.INTENT_TOGGLE2); filter.addAction(GarageToggleService.INTENT_ERROR); filter.addAction(GarageToggleService.INTENT_STATE2); registerReceiver(receiver, filter);//www . jav a 2 s .c o m // Start up the getState loop. if (application.getSelectedAccount() != null) { startStateLoop(); } // If the actvitiy was closed before the previous service started, the // buttons // will still be in a disabled state. Re-enable them here. if (!isServiceRunning(GarageToggleService.class.getName())) { enableButtons1(true); enableButtons2(true); } }
From source file:cc.arduino.mvd.services.BinocularService.java
@Override public void onCreate() { super.onCreate(); IntentFilter filter = new IntentFilter(); filter.addAction(MvdHelper.ACTION_UP); filter.addAction(MvdHelper.ACTION_DOWN); filter.addAction(MvdHelper.ACTION_KILL); registerReceiver(broadcastReceiver, filter); }
From source file:com.sqisland.android.gcm_client.Gcm.java
public void start(String sender_id_para, String sever_url_para) { mGCMReceiver = new GCMReceiver(); mOnRegisteredFilter = new IntentFilter(); mOnRegisteredFilter.addAction(Constants.ACTION_ON_REGISTERED); sender_id = sender_id_para;/* w w w . ja v a 2 s . c o m*/ server_url = sever_url_para; GCMRegistrar.checkDevice(context); GCMRegistrar.checkManifest(context); final String regId = GCMRegistrar.getRegistrationId(context); if (!regId.equals("")) { sendIdToServer(regId); } else { GCMRegistrar.register(context, sender_id); } }
From source file:com.lge.friendsCamera.MainActivity.java
private void initialize() { receiver = new WifiReceiver(); FriendsCameraApplication.setContext(this); IntentFilter filter = new IntentFilter(); filter.addAction(WifiClient.ACTION_WIFI_STATE); LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(receiver, filter); checkFileWritePermission();/* www. ja v a2s . c o m*/ fingerPrint = ""; }
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 w ww .j a va2 s. c o m*/ }
From source file:com.ironsmile.cordova.mediaevents.MediaEventListener.java
/** * Executes the request.//www . j av a 2s.c o m * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context used when calling back into js * @return True if the action was valid, false if not. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("start")) { if (this.eventCallbackContext != null) { callbackContext.error("Media event listener already running."); return true; } this.eventCallbackContext = callbackContext; // We need to listen to audio events IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { sendMediaEvent(intent); } }; cordova.getActivity().registerReceiver(this.receiver, intentFilter); } if (this.focusListener == null) { Context ctx = cordova.getActivity().getBaseContext(); this.focusListener = this.new FocusListener(ctx); } // Don't return any result now, since status results will be sent when // events come in from broadcast receiver PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); return true; } else if (action.equals("stop")) { removeMediaEventListener(); // release status callback in JS side this.sendUpdate(new JSONObject(), false); this.eventCallbackContext = null; callbackContext.success(); return true; } return false; }