List of usage examples for org.apache.http.client.utils URLEncodedUtils format
public static String format(final Iterable<? extends NameValuePair> parameters, final Charset charset)
From source file:net.java.sip.communicator.service.httputil.HttpUtils.java
/** * Posting form to <tt>address</tt>. For submission we use POST method * which is "application/x-www-form-urlencoded" encoded. * @param httpClient the http client/*w w w .j ava2 s . c o m*/ * @param postMethod the post method * @param address HTTP address. * @param formParamNames the parameter names to include in post. * @param formParamValues the corresponding parameter values to use. * @param usernameParamIx the index of the username parameter in the * <tt>formParamNames</tt> and <tt>formParamValues</tt> * if any, otherwise -1. * @param passwordParamIx the index of the password parameter in the * <tt>formParamNames</tt> and <tt>formParamValues</tt> * if any, otherwise -1. * @param headerParamNames additional header name to include * @param headerParamValues corresponding header value to include * @return the result or null if send was not possible or * credentials ask if any was canceled. */ private static HttpEntity postForm(DefaultHttpClient httpClient, HttpPost postMethod, String address, ArrayList<String> formParamNames, ArrayList<String> formParamValues, int usernameParamIx, int passwordParamIx, RedirectHandler redirectHandler, List<String> headerParamNames, List<String> headerParamValues) throws Throwable { // if we have username and password in the parameters, lets // retrieve their values // if there are already filled skip asking the user Credentials creds = null; if (usernameParamIx != -1 && usernameParamIx < formParamNames.size() && passwordParamIx != -1 && passwordParamIx < formParamNames.size() && (formParamValues.get(usernameParamIx) == null || formParamValues.get(usernameParamIx).length() == 0) && (formParamValues.get(passwordParamIx) == null || formParamValues.get(passwordParamIx).length() == 0)) { URL url = new URL(address); HTTPCredentialsProvider prov = (HTTPCredentialsProvider) httpClient.getCredentialsProvider(); // don't allow empty username while (creds == null || creds.getUserPrincipal() == null || StringUtils.isNullOrEmpty(creds.getUserPrincipal().getName())) { creds = prov.getCredentials(new AuthScope(url.getHost(), url.getPort())); // it was user canceled lets stop processing if (creds == null && !prov.retry()) { return null; } } } // construct the name value pairs we will be sending List<NameValuePair> parameters = new ArrayList<NameValuePair>(); // there can be no params if (formParamNames != null) { for (int i = 0; i < formParamNames.size(); i++) { // we are on the username index, insert retrieved username value if (i == usernameParamIx && creds != null) { parameters .add(new BasicNameValuePair(formParamNames.get(i), creds.getUserPrincipal().getName())); } // we are on the password index, insert retrieved password val else if (i == passwordParamIx && creds != null) { parameters.add(new BasicNameValuePair(formParamNames.get(i), creds.getPassword())); } else // common name value pair, all info is present { parameters.add(new BasicNameValuePair(formParamNames.get(i), formParamValues.get(i))); } } } // our custom strategy, will check redirect handler should we redirect // if missing will use the default handler httpClient.setRedirectStrategy(new CustomRedirectStrategy(redirectHandler, parameters)); // Uses String UTF-8 to keep compatible with android version and // older versions of the http client libs, as the one used // in debian (4.1.x) String s = URLEncodedUtils.format(parameters, "UTF-8"); StringEntity entity = new StringEntity(s, "UTF-8"); // set content type to "application/x-www-form-urlencoded" entity.setContentType(URLEncodedUtils.CONTENT_TYPE); // insert post values encoded. postMethod.setEntity(entity); if (headerParamNames != null) { for (int i = 0; i < headerParamNames.size(); i++) { postMethod.addHeader(headerParamNames.get(i), headerParamValues.get(i)); } } // execute post return executeMethod(httpClient, postMethod, redirectHandler, parameters); }
From source file:derson.com.httpsender.AsyncHttpClient.RequestParams.java
public String getParamString() { return URLEncodedUtils.format(getParamsList(), contentEncoding); }
From source file:tw.com.sti.store.api.android.AndroidApiService.java
/** * Search Apps(11): ???/*from w w w.j av a 2s. c o m*/ */ public ApiInvoker<AppsRet> searchApps(String query, AppsType appType, Integer appfilter, int page, Integer pSize) { String[] paramNames = null; String[] paramValues = null; if (pSize != null) { paramNames = new String[] { "query", "psize" }; paramValues = new String[] { "" + query, pSize.toString() }; } else { paramNames = new String[] { "query" }; paramValues = new String[] { "" + query }; } String url = apiUrl.getSearchAppsUrl(appType, page); ApiDataParseHandler<AppsRet> handler = ApiDataParseHandler.APPS_RET_PARSE_HANDLER; List<NameValuePair> nvps = createRequestParams(paramNames, paramValues, true, appfilter); if (Logger.DEBUG) { L.d(url + "?" + URLEncodedUtils.format(nvps, "UTF-8")); } return new ApiInvoker<AppsRet>(this.config, handler, url, nvps); }
From source file:org.dasein.cloud.skeleton.RESTMethod.java
private @Nonnull String getEndpoint(@Nonnull String resource, @Nullable String id, @Nullable NameValuePair... parameters) throws ConfigurationException, InternalException { // TODO: implement this to provide a canonical URI based on the resource and ID being references ProviderContext ctx = provider.getContext(); if (ctx == null) { throw new NoContextException(); }//from w ww .java2 s.com String endpoint = ctx.getEndpoint(); if (endpoint == null) { logger.error("Null endpoint for the MyCloud cloud"); throw new ConfigurationException("Null endpoint for MyCloud cloud"); } while (endpoint.endsWith("/") && !endpoint.equals("/")) { endpoint = endpoint.substring(0, endpoint.length() - 1); } if (resource.startsWith("/")) { endpoint = endpoint + resource; } else { endpoint = endpoint + "/" + resource; } if (id != null) { if (endpoint.endsWith("/")) { endpoint = endpoint + id; } else { endpoint = endpoint + "/" + id; } } if (parameters != null && parameters.length > 0) { while (endpoint.endsWith("/")) { endpoint = endpoint.substring(0, endpoint.length() - 1); } endpoint = endpoint + "?"; ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); Collections.addAll(params, parameters); endpoint = endpoint + URLEncodedUtils.format(params, "utf-8"); } return endpoint; }
From source file:com.nexmo.messaging.sdk.NexmoSmsClient.java
/** * submit a message submission request object. * This will use the supplied object to construct a request and post it to the Nexmo REST interface.<br> * This method will respond with an array of SmsSubmissionResult objects. Depending on the nature and length of the submitted message, Nexmo may automatically * split the message into multiple sms messages in order to deliver to the handset. For example, a long text sms of greater than 160 chars will need to be split * into multiple 'concatenated' sms messages. The Nexmo service will handle this automatically for you.<br> * The array of SmsSubmissionResult objects will contain a SmsSubmissionResult object for every actual sms that was required to submit the message. * each message can potentially have a different status result, and each message will have a different message id. * Delivery notifications will be generated for each sms message within this set and will be posted to your application containing the appropriate message id. * * @param message The message request object that describes the type of message and the contents to be submitted. * @param validityPeriod The validity period (Time-To-Live) for this message. Specifies the time before this mesage will be expired if not yet delivered * @param networkCode (Optional) use this parameter to force this message to be associated with and delivered on this network. Use this in cases where you want to over-ride * the automatic network detection provided by Nexmo. This value will be used in order to determine the pricing and routing for this message.<br> * (Note) This feature must be enabled and available on your account or else this value will be ignored. * @param performReachabilityCheck Flag to indicate wether a reachability check should be performed on this message before delivery is attempted. If the destination is * not reachable, the message will be rejected and a reachability status will be returned in the response field smsSubmissionReachabilityStatus<br> * (Note) This feature must be enabled and available on your account or else the message request will be rejected. There may be additional cost * associated with the use of this feature. * * @return SmsSubmissionResult[] an array of results, 1 object for each sms message that was required to submit this message in its entirety * * @throws Exception There has been a general failure either within the Client class, or whilst attempting to communicate with the Nexmo service (eg, Network failure) *//* w w w. j a va 2 s.co m*/ public SmsSubmissionResult[] submitMessage(final Message message, final ValidityPeriod validityPeriod, final String networkCode, final boolean performReachabilityCheck) throws Exception { log.debug("HTTP-Message-Submission Client .. from [ " + message.getFrom() + " ] to [ " + message.getTo() + " ] msg [ " + message.getMessageBody() + " ] "); // From the Message object supplied, construct an appropriate request to be submitted to the Nexmo REST Service. // Determine what 'product' type we are submitting, and select the appropriate endpoint path String submitPath = SUBMISSION_PATH_SMS; // Determine the type parameter based on the type of Message object. boolean binary = message.getType() == Message.MESSAGE_TYPE_BINARY; boolean unicode = message.isUnicode(); boolean wapPush = message.getType() == Message.MESSAGE_TYPE_WAPPUSH; String mode = "text"; if (binary) mode = "binary"; if (unicode) mode = "unicode"; if (wapPush) mode = "wappush"; // Construct a query string as a list of NameValuePairs List<NameValuePair> params = new ArrayList<>(); boolean doPost = false; params.add(new BasicNameValuePair("api_key", this.apiKey)); if (!this.signRequests) params.add(new BasicNameValuePair("api_secret", this.apiSecret)); params.add(new BasicNameValuePair("from", message.getFrom())); params.add(new BasicNameValuePair("to", message.getTo())); params.add(new BasicNameValuePair("type", mode)); if (wapPush) { params.add(new BasicNameValuePair("url", message.getWapPushUrl())); params.add(new BasicNameValuePair("title", message.getWapPushTitle())); if (message.getWapPushValidity() > 0) params.add(new BasicNameValuePair("validity", "" + message.getWapPushValidity())); } else if (binary) { // Binary Message if (message.getBinaryMessageUdh() != null) params.add(new BasicNameValuePair("udh", HexUtil.bytesToHex(message.getBinaryMessageUdh()))); params.add(new BasicNameValuePair("body", HexUtil.bytesToHex(message.getBinaryMessageBody()))); } else { // Text Message params.add(new BasicNameValuePair("text", message.getMessageBody())); if (message.getMessageBody() != null && message.getMessageBody().length() > 255) doPost = true; } if (message.getClientReference() != null) params.add(new BasicNameValuePair("client-ref", message.getClientReference())); params.add(new BasicNameValuePair("status-report-req", "" + message.getStatusReportRequired())); if (message.getMessageClass() != null) params.add(new BasicNameValuePair("message-class", "" + message.getMessageClass().getMessageClass())); if (message.getProtocolId() != null) params.add(new BasicNameValuePair("protocol-id", "" + message.getProtocolId())); if (validityPeriod != null) { if (validityPeriod.getTimeToLive() != null) params.add(new BasicNameValuePair("ttl", "" + validityPeriod.getTimeToLive().intValue())); if (validityPeriod.getValidityPeriodHours() != null) params.add(new BasicNameValuePair("ttl-hours", "" + validityPeriod.getValidityPeriodHours().intValue())); if (validityPeriod.getValidityPeriodMinutes() != null) params.add(new BasicNameValuePair("ttl-minutes", "" + validityPeriod.getValidityPeriodMinutes().intValue())); if (validityPeriod.getValidityPeriodSeconds() != null) params.add(new BasicNameValuePair("ttl-seconds", "" + validityPeriod.getValidityPeriodSeconds().intValue())); } if (networkCode != null) params.add(new BasicNameValuePair("network-code", networkCode)); if (performReachabilityCheck) params.add(new BasicNameValuePair("test-reachable", "true")); if (this.signRequests) RequestSigning.constructSignatureForRequestParameters(params, this.signatureSecretKey); String baseUrl = this.baseUrlHttps + submitPath; // Now that we have generated a query string, we can instanciate a HttpClient, // construct a POST or GET method and execute to submit the request String response = null; for (int pass = 1; pass <= 2; pass++) { HttpUriRequest method = null; doPost = true; String url = null; if (doPost) { HttpPost httpPost = new HttpPost(baseUrl); httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); method = httpPost; url = baseUrl + "?" + URLEncodedUtils.format(params, "utf-8"); } else { String query = URLEncodedUtils.format(params, "utf-8"); method = new HttpGet(baseUrl + "?" + query); url = method.getRequestLine().getUri(); } try { if (this.httpClient == null) this.httpClient = HttpClientUtils.getInstance(this.connectionTimeout, this.soTimeout) .getNewHttpClient(); HttpResponse httpResponse = this.httpClient.execute(method); int status = httpResponse.getStatusLine().getStatusCode(); if (status != 200) throw new Exception( "got a non-200 response [ " + status + " ] from Nexmo-HTTP for url [ " + url + " ] "); response = new BasicResponseHandler().handleResponse(httpResponse); log.info(".. SUBMITTED NEXMO-HTTP URL [ " + url + " ] -- response [ " + response + " ] "); break; } catch (Exception e) { method.abort(); log.info("communication failure: " + e); String exceptionMsg = e.getMessage(); if (exceptionMsg.indexOf("Read timed out") >= 0) { log.info( "we're still connected, but the target did not respond in a timely manner .. drop ..."); } else { if (pass == 1) { log.info("... re-establish http client ..."); this.httpClient = null; continue; } } // return a COMMS failure ... SmsSubmissionResult[] results = new SmsSubmissionResult[1]; results[0] = new SmsSubmissionResult(SmsSubmissionResult.STATUS_COMMS_FAILURE, null, null, "Failed to communicate with NEXMO-HTTP url [ " + url + " ] ..." + e, message.getClientReference(), null, null, true, null, null); return results; } } // parse the response doc ... /* We receive a response from the api that looks like this, parse the document and turn it into an array of SmsSubmissionResult, one object per <message> node <mt-submission-response> <messages count='x'> <message> <to>xxx</to> <messageId>xxx</messageId> <status>xx</status> <errorText>ff</errorText> <clientRef>xxx</clientRef> <remainingBalance>##.##</remainingBalance> <messagePrice>##.##</messagePrice> <reachability status='x' description='xxx' /> <network>23410</network> </message> </messages> </mt-submission-response> */ List<SmsSubmissionResult> results = new ArrayList<>(); Document doc = null; synchronized (this.documentBuilder) { try { doc = this.documentBuilder.parse(new InputSource(new StringReader(response))); } catch (Exception e) { throw new Exception("Failed to build a DOM doc for the xml document [ " + response + " ] ", e); } } NodeList replies = doc.getElementsByTagName("mt-submission-response"); for (int i = 0; i < replies.getLength(); i++) { Node reply = replies.item(i); NodeList messageLists = reply.getChildNodes(); for (int i2 = 0; i2 < messageLists.getLength(); i2++) { Node messagesNode = messageLists.item(i2); if (messagesNode.getNodeType() != Node.ELEMENT_NODE) continue; if (messagesNode.getNodeName().equals("messages")) { NodeList messages = messagesNode.getChildNodes(); for (int i3 = 0; i3 < messages.getLength(); i3++) { Node messageNode = messages.item(i3); if (messageNode.getNodeType() != Node.ELEMENT_NODE) continue; int status = -1; String messageId = null; String destination = null; String errorText = null; String clientReference = null; BigDecimal remainingBalance = null; BigDecimal messagePrice = null; SmsSubmissionReachabilityStatus smsSubmissionReachabilityStatus = null; String network = null; NodeList nodes = messageNode.getChildNodes(); for (int i4 = 0; i4 < nodes.getLength(); i4++) { Node node = nodes.item(i4); if (node.getNodeType() != Node.ELEMENT_NODE) continue; if (node.getNodeName().equals("messageId")) { messageId = node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue(); } else if (node.getNodeName().equals("to")) { destination = node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue(); } else if (node.getNodeName().equals("status")) { String str = node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue(); try { status = Integer.parseInt(str); } catch (NumberFormatException e) { log.error("xml parser .. invalid value in <status> node [ " + str + " ] "); status = SmsSubmissionResult.STATUS_INTERNAL_ERROR; } } else if (node.getNodeName().equals("errorText")) { errorText = node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue(); } else if (node.getNodeName().equals("clientRef")) { clientReference = node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue(); } else if (node.getNodeName().equals("remainingBalance")) { String str = node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue(); try { if (str != null) remainingBalance = new BigDecimal(str); } catch (NumberFormatException e) { log.error("xml parser .. invalid value in <remainingBalance> node [ " + str + " ] "); } } else if (node.getNodeName().equals("messagePrice")) { String str = node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue(); try { if (str != null) messagePrice = new BigDecimal(str); } catch (NumberFormatException e) { log.error( "xml parser .. invalid value in <messagePrice> node [ " + str + " ] "); } } else if (node.getNodeName().equals("reachability")) { NamedNodeMap attributes = node.getAttributes(); Node attr = attributes.getNamedItem("status"); String str = attr == null ? "" + SmsSubmissionReachabilityStatus.REACHABILITY_STATUS_UNKNOWN : attr.getNodeValue(); int reachabilityStatus = SmsSubmissionReachabilityStatus.REACHABILITY_STATUS_UNKNOWN; try { reachabilityStatus = Integer.parseInt(str); } catch (NumberFormatException e) { log.error( "xml parser .. invalid value in 'status' attribute in <reachability> node [ " + str + " ] "); reachabilityStatus = SmsSubmissionReachabilityStatus.REACHABILITY_STATUS_UNKNOWN; } attr = attributes.getNamedItem("description"); String description = attr == null ? "-UNKNOWN-" : attr.getNodeValue(); smsSubmissionReachabilityStatus = new SmsSubmissionReachabilityStatus( reachabilityStatus, description); } else if (node.getNodeName().equals("network")) { network = node.getFirstChild() == null ? null : node.getFirstChild().getNodeValue(); } else log.error( "xml parser .. unknown node found in status-return, expected [ messageId, to, status, errorText, clientRef, messagePrice, remainingBalance, reachability, network ] -- found [ " + node.getNodeName() + " ] "); } if (status == -1) throw new Exception("Xml Parser - did not find a <status> node"); // Is this a temporary error ? boolean temporaryError = (status == SmsSubmissionResult.STATUS_THROTTLED || status == SmsSubmissionResult.STATUS_INTERNAL_ERROR || status == SmsSubmissionResult.STATUS_TOO_MANY_BINDS); results.add(new SmsSubmissionResult(status, destination, messageId, errorText, clientReference, remainingBalance, messagePrice, temporaryError, smsSubmissionReachabilityStatus, network)); } } } } return results.toArray(new SmsSubmissionResult[results.size()]); }
From source file:com.esri.geoevent.datastore.GeoEventDataStoreProxy.java
private URI createDestinationURI(ServerInfo serverInfo, String path, MessageContext msgContext) { try {/*from w w w . j a v a 2 s .com*/ if (serverInfo.tokenExpiration == null) { getTokenForServer(serverInfo, msgContext); } StringBuilder sb = new StringBuilder(); sb.append(serverInfo.url.toExternalForm()); if (sb.charAt(sb.length() - 1) != '/') { sb.append('/'); } sb.append(path); String queryString = msgContext.getHttpServletRequest().getQueryString(); String tokenToUse = null; if (serverInfo.encryptedToken != null) { tokenToUse = Crypto.doDecrypt(serverInfo.encryptedToken); } if (!StringUtils.isEmpty(queryString)) { sb.append('?'); if (serverInfo.tokenExpiration == null || System.currentTimeMillis() > serverInfo.tokenExpiration) { getTokenForServer(serverInfo, msgContext); } List<NameValuePair> params = parseQueryStringAndAddToken(queryString, tokenToUse); sb.append(URLEncodedUtils.format(params, "UTF-8")); } else if (tokenToUse != null) { sb.append("?token="); sb.append(tokenToUse); } return new URI(sb.toString()); } catch (Throwable t) { throw new RuntimeException(t); } }
From source file:com.snaptic.api.SnapticAPI.java
private HttpResponse performGET(String method, List<NameValuePair> httpParams) { HttpGet httpget;//from w w w . j av a2s .co m if (httpParams == null || httpParams.isEmpty()) { httpget = new HttpGet(SNAPTIC_BASE_URL + method); } else { httpget = new HttpGet(SNAPTIC_BASE_URL + method + '?' + URLEncodedUtils.format(httpParams, "UTF-8")); } httpget.addHeader("Authorization", basicUserAuth); HttpResponse response = null; try { response = httpClient.execute(httpget); } catch (ClientProtocolException e) { log("caught ClientProtocolException performing GET " + httpget.getURI()); e.printStackTrace(); return null; } catch (IOException e) { log("caught IOException performing GET " + httpget.getURI()); e.printStackTrace(); return null; } sync_trace("GET " + httpget.getURI() + " returned " + response.getStatusLine().getStatusCode() + ' ' + response.getStatusLine().getReasonPhrase()); return response; }
From source file:tw.com.sti.store.api.android.AndroidApiService.java
/** * CPs Apps(12): ??/*from ww w . ja v a2 s. com*/ */ public ApiInvoker<CPAppsRet> cpApps(String cpId, AppsType appsType, Integer appfilter, int page, Integer pSize) { String url = apiUrl.getCPAppsUrl(cpId, appsType, page); ApiDataParseHandler<CPAppsRet> handler = ApiDataParseHandler.CP_APPS_RET_PARSE_HANDLER; String[] paramNames = null; String[] paramValues = null; if (pSize != null) { paramNames = new String[] { "psize" }; paramValues = new String[] { pSize.toString() }; } List<NameValuePair> nvps = createRequestParams(paramNames, paramValues, true, appfilter); if (Logger.DEBUG) { L.d(url + "?" + URLEncodedUtils.format(nvps, "UTF-8")); } return new ApiInvoker<CPAppsRet>(this.config, handler, url, nvps); }
From source file:org.dvbviewer.controller.ui.fragments.ChannelEpg.java
@Override public boolean onContextItemSelected(MenuItem item) { if (item.getMenuInfo() != null) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); selectedPosition = info.position; }/*from ww w. j av a 2s . c o m*/ Cursor c; c = mAdapter.getCursor(); c.moveToPosition(selectedPosition); Timer timer; if (getUserVisibleHint()) { switch (item.getItemId()) { case R.id.menuRecord: timer = cursorToTimer(c); String url = timer.getId() <= 0l ? ServerConsts.URL_TIMER_CREATE : ServerConsts.URL_TIMER_EDIT; String title = timer.getTitle(); String days = String.valueOf(DateUtils.getDaysSinceDelphiNull(timer.getStart())); String start = String.valueOf(DateUtils.getMinutesOfDay(timer.getStart())); String stop = String.valueOf(DateUtils.getMinutesOfDay(timer.getEnd())); String endAction = String.valueOf(timer.getTimerAction()); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("ch", String.valueOf(timer.getChannelId()))); params.add(new BasicNameValuePair("dor", days)); params.add(new BasicNameValuePair("encoding", "255")); params.add(new BasicNameValuePair("enable", "1")); params.add(new BasicNameValuePair("start", start)); params.add(new BasicNameValuePair("stop", stop)); params.add(new BasicNameValuePair("title", title)); params.add(new BasicNameValuePair("endact", endAction)); if (timer.getId() > 0) { params.add(new BasicNameValuePair("id", String.valueOf(timer.getId()))); } String query = URLEncodedUtils.format(params, "utf-8"); String request = url + query; RecordingServiceGet rsGet = new RecordingServiceGet(request); Thread executionThread = new Thread(rsGet); executionThread.start(); return true; case R.id.menuTimer: timer = cursorToTimer(c); if (!UIUtils.isTablet(getActivity())) { Intent timerIntent = new Intent(getActivity(), TimerDetailsActivity.class); timerIntent.putExtra(TimerDetails.EXTRA_TITLE, timer.getTitle()); timerIntent.putExtra(TimerDetails.EXTRA_CHANNEL_NAME, timer.getChannelName()); timerIntent.putExtra(TimerDetails.EXTRA_CHANNEL_ID, timer.getChannelId()); timerIntent.putExtra(TimerDetails.EXTRA_START, timer.getStart().getTime()); timerIntent.putExtra(TimerDetails.EXTRA_END, timer.getEnd().getTime()); startActivity(timerIntent); } return true; case R.id.menuDetails: Intent details = new Intent(getActivity(), IEpgDetailsActivity.class); c = mAdapter.getCursor(); c.moveToPosition(selectedPosition); IEPG entry = cursorToEpgEntry(c); details.putExtra(IEPG.class.getSimpleName(), entry); startActivity(details); return true; default: break; } } return false; }