List of usage examples for android.content Intent getAction
public @Nullable String getAction()
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 ww . j a va 2 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:ca.appvelopers.mcgillmobile.ui.BaseActivity.java
/** * Handles the reception of broadcasts. Should be overridden in subclasses that have extra * receiver actions// w w w. j a v a 2 s . co m * * @param intent The broadcasted intent */ @CallSuper protected void onReceivedBroadcast(Intent intent) { switch (intent.getAction()) { case Constants.BROADCAST_MINERVA: //Log the user out clearManager.all(); //Bring them back to the SplashActivity with an exception Intent intent1 = new Intent(this, SplashActivity.class).putExtra(Constants.EXCEPTION, new MinervaException()); startActivity(intent1); finish(); } }
From source file:com.freshplanet.nativeExtensions.C2DMBroadcastReceiver.java
/** * When a cd2m intent is received by the device. * Filter the type of intent./*from w w w .j av a2s . c o m*/ * <ul> * <li>REGISTRATION : get the token and send it to the AS</li> * <li>RECEIVE : create a notification with the intent parameters</li> * </ul> */ @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION")) { handleRegistration(context, intent); } else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE") && !C2DMExtension.isInForeground) { handleMessage(context, intent);//display the notification only when in background } }
From source file:com.liferay.alerts.activity.CommentsActivity.java
private void _registerBroadcastReceiver() { IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_ADD_COMMENT); filter.addAction(ACTION_UPDATE_COMMENTS_LIST); _receiver = new BroadcastReceiver() { @Override//from www . ja v a 2s. co m public void onReceive(Context context, Intent intent) { String action = intent.getAction(); ListView listView = (ListView) findViewById(R.id.comments); if (ACTION_UPDATE_COMMENTS_LIST.equals(action)) { ArrayList<Alert> alerts = intent.getParcelableArrayListExtra(EXTRA_ALERTS); ArrayAdapter<Alert> adapter = new CommentListAdapter(getApplicationContext(), alerts); listView.setAdapter(adapter); } else if (ACTION_ADD_COMMENT.equals(action)) { Alert alert = intent.getParcelableExtra(EXTRA_ALERT); ArrayAdapter<Alert> adapter = (ArrayAdapter<Alert>) listView.getAdapter(); adapter.add(alert); } } }; _getBroadcastManager().registerReceiver(_receiver, filter); }
From source file:com.BeeFramework.activity.MainActivity.java
/** * ?Intent//from ww w .j a va 2 s . c o m * * @param intent * intent */ private void handleIntent(Intent intent) { String action = intent.getAction(); if (ACTION_RESPONSE.equals(action)) { String method = intent.getStringExtra(RESPONSE_METHOD); if (PushConstants.METHOD_BIND.equals(method)) { int errorCode = intent.getIntExtra(RESPONSE_ERRCODE, 0); if (errorCode == 0) { String content = intent.getStringExtra(RESPONSE_CONTENT); String appid = ""; String channelid = ""; String userid = ""; try { JSONObject jsonContent = new JSONObject(content); JSONObject params = jsonContent.getJSONObject("response_params"); appid = params.getString("appid"); channelid = params.getString("channel_id"); userid = params.getString("user_id"); editor.putString("UUID", userid); editor.commit(); } catch (JSONException e) { } } else { } } } else if (ACTION_LOGIN.equals(action)) { String accessToken = intent.getStringExtra(EXTRA_ACCESS_TOKEN); PushManager.startWork(getApplicationContext(), PushConstants.LOGIN_TYPE_ACCESS_TOKEN, accessToken); } else if (ACTION_MESSAGE.equals(action)) { String message = intent.getStringExtra(EXTRA_MESSAGE); String summary = "Receive message from server:\n\t"; JSONObject contentJson = null; String contentStr = message; try { contentJson = new JSONObject(message); contentStr = contentJson.toString(4); } catch (JSONException e) { } summary += contentStr; } else if (ACTION_PUSHCLICK.equals(action)) { String message = intent.getStringExtra(CUSTOM_CONTENT); } }
From source file:com.google.android.panoramio.ImageGrid.java
private void handleIntent(Intent intent) throws IOException, URISyntaxException, JSONException { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { query = intent.getStringExtra(SearchManager.QUERY); } else {// w w w .j a v a 2 s.co m query = intent.getStringExtra("query"); } if (query == null || query.isEmpty()) { query = DEFAULT_QUERY; } // Start downloading mImageManager.load(query); }
From source file:com.lhtechnologies.DoorApp.AuthenticatorService.java
@Override protected void onHandleIntent(Intent intent) { if (intent.getAction().equals(stopAction)) { stopSelf();//from w ww .ja v a2 s. c o m } else if (intent.getAction().equals(authenticateAction)) { //Check if we want to open the front door or flat door String doorToOpen = FrontDoor; String authCode = null; if (intent.hasExtra(FlatDoor)) { doorToOpen = FlatDoor; authCode = intent.getCharSequenceExtra(FlatDoor).toString(); } if (intent.hasExtra(LetIn)) { doorToOpen = LetIn; } //Now run the connection code (Hope it runs asynchronously and we do not need AsyncTask --- NOPE --YES urlConnection = null; URL url; //Prepare the return intent Intent broadcastIntent = new Intent(AuthenticationFinishedBroadCast); try { //Try to create the URL, return an error if it fails url = new URL(address); if (!url.getProtocol().equals("https")) { throw new MalformedURLException("Please only use https protocol!"); } String password = "password"; KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(getResources().getAssets().open("LH Technologies Root CA.bks"), password.toCharArray()); TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509"); tmf.init(keyStore); SSLContext context = SSLContext.getInstance("TLS"); context.init(null, tmf.getTrustManagers(), null); urlConnection = (HttpsURLConnection) url.openConnection(); urlConnection.setSSLSocketFactory(context.getSocketFactory()); urlConnection.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); urlConnection.setConnectTimeout(15000); urlConnection.setRequestMethod("POST"); urlConnection.setDoOutput(true); urlConnection.setChunkedStreamingMode(0); OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream()); //Write our stuff to the output stream; out.write("deviceName=" + deviceName + "&udid=" + udid + "&secret=" + secret + "&clientVersion=" + clientVersion + "&doorToOpen=" + doorToOpen); if (doorToOpen.equals(FlatDoor)) { out.write("&authCode=" + authCode); //Put an extra in so the return knows we opened the flat door broadcastIntent.putExtra(FlatDoor, FlatDoor); } out.close(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); //Read the answer String decodedString; String returnString = ""; while ((decodedString = in.readLine()) != null) { returnString += decodedString; } in.close(); broadcastIntent.putExtra(AuthenticatorReturnCode, returnString); } catch (MalformedURLException e) { broadcastIntent.putExtra(AuthenticatorReturnCode, ClientErrorMalformedURL); } catch (Exception e) { broadcastIntent.putExtra(AuthenticatorReturnCode, ClientErrorUndefined); broadcastIntent.putExtra(AuthenticatorErrorDescription, e.getLocalizedMessage()); } finally { if (urlConnection != null) urlConnection.disconnect(); //Now send a broadcast with the result sendOrderedBroadcast(broadcastIntent, null); Log.e(this.getClass().getSimpleName(), "Send Broadcast!"); } } }
From source file:fr.cph.chicago.activity.SearchActivity.java
/** * Reload adapter with correct data/* ww w .j a va 2 s.c o m*/ * * @param intent * the intent */ private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); DataHolder dataHolder = DataHolder.getInstance(); BusData busData = dataHolder.getBusData(); TrainData trainData = dataHolder.getTrainData(); List<Station> foundStations = new ArrayList<Station>(); for (Entry<TrainLine, List<Station>> e : trainData.getAllStations().entrySet()) { for (Station station : e.getValue()) { boolean res = StringUtils.containsIgnoreCase(station.getName(), query.trim()); if (res) { if (!foundStations.contains(station)) { foundStations.add(station); } } } } List<BusRoute> foundBusRoutes = new ArrayList<BusRoute>(); for (BusRoute busRoute : busData.getRoutes()) { boolean res = StringUtils.containsIgnoreCase(busRoute.getId(), query.trim()) || StringUtils.containsIgnoreCase(busRoute.getName(), query.trim()); if (res) { if (!foundBusRoutes.contains(busRoute)) { foundBusRoutes.add(busRoute); } } } List<BikeStation> foundBikeStations = new ArrayList<BikeStation>(); if (mBikeStations != null) { for (BikeStation bikeStation : mBikeStations) { boolean res = StringUtils.containsIgnoreCase(bikeStation.getName(), query.trim()) || StringUtils.containsIgnoreCase(bikeStation.getStAddress1(), query.trim()); if (res) { if (!foundBikeStations.contains(bikeStation)) { foundBikeStations.add(bikeStation); } } } } mAdapter.updateData(foundStations, foundBusRoutes, foundBikeStations); mAdapter.notifyDataSetChanged(); } }
From source file:com.esminis.server.library.service.server.installpackage.InstallerPackage.java
private void stopServer(Context context, ServerControl serverControl) { final CyclicBarrier barrier = new CyclicBarrier(2); final BroadcastReceiver receiver = new BroadcastReceiver() { @Override//from w w w. java 2 s . c om public void onReceive(Context context, Intent intent) { if (intent.getAction() == null || !intent.getAction().equals(MainActivity.getIntentActionServerStatus(context))) { return; } final Bundle extras = intent.getExtras(); if (extras == null || extras.containsKey("errorLine") || extras.getBoolean("running")) { return; } try { barrier.await(); } catch (InterruptedException | BrokenBarrierException ignored) { } } }; context.registerReceiver(receiver, new IntentFilter(MainActivity.getIntentActionServerStatus(context))); preferences.set(context, Preferences.SERVER_STARTED, false); serverControl.requestStop(null); try { barrier.await(); } catch (InterruptedException | BrokenBarrierException ignored) { } context.unregisterReceiver(receiver); }
From source file:alaindc.crowdroid.View.StakeholdersActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stakeholders); linearLayout = (LinearLayout) findViewById(R.id.subscribesLinearLayout); updateStakeButton = (Button) findViewById(R.id.updateStakeButton); sendStakeButton = (Button) findViewById(R.id.sendStakeButton); updateStakeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_GETSUBSCRIPTION); getApplicationContext().startService(subscrIntent); }/* ww w .ja v a2 s.c o m*/ }); sendStakeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { JSONArray jsonArr = new JSONArray(); JSONObject jsonObj = new JSONObject(); jsonObj.put("user", RadioUtils.getMyDeviceId(getApplicationContext())); jsonArr.put(jsonObj); for (int i = 0; i < linearLayout.getChildCount(); i++) { View view = linearLayout.getChildAt(i); if (view instanceof CheckBox) { CheckBox c = (CheckBox) view; if (c.isChecked()) { jsonObj = new JSONObject(); jsonObj.put("id", c.getId()); jsonArr.put(jsonObj); } } } String body = jsonArr.toString(); Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_UPDATESUBSCRIPTION); subscrIntent.putExtra(Constants.EXTRA_BODY_UPDATESUBSCRIPTION, body); getApplicationContext().startService(subscrIntent); } catch (JSONException e) { return; } } }); Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_GETSUBSCRIPTION); getApplicationContext().startService(subscrIntent); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Constants.INTENTVIEW_RECEIVED_SUBSCRIPTION)) { String response = intent.getStringExtra(Constants.EXTRAVIEW_RECEIVED_SUBSCRIPTION); //Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show(); linearLayout.removeAllViews(); try { JSONArray jsonArray = new JSONArray(response); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); int id = jsonObject.getInt("id"); String name = jsonObject.getString("name"); boolean subscribed = jsonObject.getInt("subscribed") == 1; CheckBox checkBox = new CheckBox(getApplicationContext()); checkBox.setTextColor(Color.BLACK); checkBox.setText(name); checkBox.setId(id); checkBox.setChecked(subscribed); linearLayout.addView(checkBox); int idx = linearLayout.indexOfChild(checkBox); checkBox.setTag(Integer.toString(idx)); } } catch (JSONException e) { return; } } else { Log.d("", ""); } } }; IntentFilter rcvDataIntFilter = new IntentFilter(Constants.INTENTVIEW_RECEIVED_SUBSCRIPTION); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, rcvDataIntFilter); }