List of usage examples for android.os Message setData
public void setData(Bundle data)
From source file:fr.julienvermet.bugdroid.service.CommentIntentService.java
private void sendResult(Intent intent, int statusCode, String result) { Bundle extras = intent.getExtras();/* w w w .jav a2s. c o m*/ Messenger messenger = (Messenger) extras.get(MESSENGER); if (messenger != null) { Message msg = Message.obtain(); Bundle data = new Bundle(); data.putInt(STATUS_CODE, statusCode); data.putString(RESULT, result); msg.setData(data); try { messenger.send(msg); } catch (android.os.RemoteException e1) { Log.w(getClass().getName(), "Exception sending message", e1); } } }
From source file:com.softminds.matrixcalculator.OperationFragments.InverseFragment.java
public void RunNewGetInverse(final int pos, final ProgressDialog pq) { Runnable runnable = new Runnable() { @Override/*from w ww . ja va 2s . c om*/ public void run() { MatrixV2 res = SquareList.get(pos).getInverse(pq); Message message = new Message(); if (res != null) { message.setData(res.getDataBundled()); myHandler.sendMessage(message); } else { myHandler.postDelayed(new Runnable() { @Override public void run() { Toast.makeText(getContext(), R.string.NoInverse, Toast.LENGTH_SHORT).show(); } }, 0); pq.dismiss(); } } }; Thread thread = new Thread(runnable); thread.start(); }
From source file:fr.julienvermet.bugdroid.service.ProductsIntentService.java
private void sendResult(Intent intent, ArrayList<Product> products) { Bundle extras = intent.getExtras();//from ww w .j ava 2s . c o m Messenger messenger = (Messenger) extras.get(MESSENGER); if (messenger != null) { Message msg = Message.obtain(); Bundle data = new Bundle(); data.putSerializable(PRODUCTS, products); msg.setData(data); try { messenger.send(msg); } catch (android.os.RemoteException e1) { Log.w(getClass().getName(), "Exception sending message", e1); } } }
From source file:id.nci.stm_9.SetPassphraseDialogFragment.java
/** * Send message back to handler which is initialized in a activity * /*from ww w . ja va 2 s . co m*/ * @param what * Message integer you want to send */ private void sendMessageToHandler(Integer what, Bundle data) { Message msg = Message.obtain(); msg.what = what; if (data != null) { msg.setData(data); } try { mMessenger.send(msg); } catch (RemoteException e) { Log.w("stm-9", "Exception sending message, Is handler present?", e); } catch (NullPointerException e) { Log.w("stm-9", "Messenger is null!", e); } }
From source file:com.gmail.at.faint545.services.DataQueueService.java
@Override protected void onHandleIntent(Intent intent) { String url = intent.getStringExtra("url"); String api = intent.getStringExtra("api"); StringBuilder results = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost(url); ArrayList<NameValuePair> arguments = new ArrayList<NameValuePair>(); arguments.add(new BasicNameValuePair(SabnzbdConstants.APIKEY, api)); arguments.add(new BasicNameValuePair(SabnzbdConstants.OUTPUT, SabnzbdConstants.OUTPUT_JSON)); arguments.add(new BasicNameValuePair(SabnzbdConstants.MODE, SabnzbdConstants.MODE_QUEUE)); try {// w ww. j ava2s . co m request.setEntity(new UrlEncodedFormEntity(arguments)); HttpResponse result = client.execute(request); InputStream inStream = result.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(inStream), 8); String line; while ((line = br.readLine()) != null) { if (line.length() > 0) { results.append(line); } } br.close(); inStream.close(); Bundle extras = intent.getExtras(); Messenger messenger = (Messenger) extras.get("messenger"); Message message = Message.obtain(); Bundle resultsBundle = new Bundle(); resultsBundle.putString("results", results.toString()); message.setData(resultsBundle); messenger.send(message); stopSelf(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } }
From source file:com.nextgis.uikobserver.HttpSendData.java
@Override protected Void doInBackground(String... urls) { if (IsNetworkAvailible(mContext)) { String sPostBody = urls[0]; // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://gis-lab.info:8090/"); HttpParams params = httppost.getParams(); params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE); HttpContext localContext = new BasicHttpContext(); try {/*from w w w .j a v a2s.co m*/ StringEntity se = new StringEntity(sPostBody, "UTF8"); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); httppost.setHeader("Content-type", "application/json"); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost, localContext); Bundle bundle = new Bundle(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { bundle.putBoolean("error", false); } else { bundle.putBoolean("error", true); } bundle.putInt("src", mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } catch (ClientProtocolException e) { mError = e.getMessage(); cancel(true); } catch (IOException e) { mError = e.getMessage(); cancel(true); } } else { Bundle bundle = new Bundle(); bundle.putBoolean("error", true); bundle.putString("err_msq", mContext.getString(R.string.sNetworkUnreach)); bundle.putInt("src", mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } return null; }
From source file:id.nci.stm_9.FileDialogFragment.java
/** * Send message back to handler which is initialized in a activity * /* w ww . j a v a2s . c o m*/ * @param what * Message integer you want to send */ private void sendMessageToHandler(Integer what, Bundle data) { Message msg = Message.obtain(); msg.what = what; if (data != null) { msg.setData(data); } try { mMessenger.send(msg); } catch (RemoteException e) { Log.w("Stm-9", "Exception sending message, Is handler present?", e); } catch (NullPointerException e) { Log.w("Stm-9", "Messenger is null!", e); } }
From source file:com.bufarini.reminders.collaboration.GMailFeedReader.java
@Override public void run() { try {//from w w w . ja va 2 s . c o m while (true) { String contents = getHttpResponse(); ArrayList<MailEntry> entries = parseGMailXmlFeed(contents); Message message = myHandler.obtainMessage(); Bundle bundle = new Bundle(); bundle.putSerializable("emails", entries); message.setData(bundle); myHandler.sendMessage(message); Thread.sleep(FIVE_MINUTES); } } catch (InterruptedException e) { // Nothing to do - exits cleanly from thread } }
From source file:com.nextgis.metroaccess.MetaDownloader.java
@Override protected Void doInBackground(String... urls) { if (IsNetworkAvailible(moContext)) { try {// www .ja v a2 s . c om String sURL = urls[0]; moHTTPGet = new HttpGet(sURL); Log.d(TAG, "HTTPGet URL " + sURL); HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 1500; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpClient Client = new DefaultHttpClient(httpParameters); HttpResponse response = Client.execute(moHTTPGet); if (response == null) return null; HttpEntity entity = response.getEntity(); if (moEventReceiver != null) { if (entity != null) { Bundle bundle = new Bundle(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { bundle.putBoolean(BUNDLE_ERRORMARK_KEY, false); msContent = EntityUtils.toString(entity, HTTP.UTF_8); bundle.putString(BUNDLE_PAYLOAD_KEY, msContent); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); } else { bundle.putBoolean(BUNDLE_ERRORMARK_KEY, true); bundle.putString(BUNDLE_MSG_KEY, moContext.getString(R.string.sNetworkGetErr)); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); } Message oMsg = new Message(); oMsg.setData(bundle); moEventReceiver.sendMessage(oMsg); } else { msError = moContext.getString(R.string.sNetworkUnreachErr); } } } catch (ClientProtocolException e) { msError = e.getMessage(); //cancel(true); } catch (IOException e) { msError = e.getMessage(); //cancel(true); } } else { if (moEventReceiver != null) { Bundle bundle = new Bundle(); bundle.putBoolean(BUNDLE_ERRORMARK_KEY, true); bundle.putString(BUNDLE_MSG_KEY, moContext.getString(R.string.sNetworkUnreachErr)); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); Message oMsg = new Message(); oMsg.setData(bundle); moEventReceiver.sendMessage(oMsg); } } return null; }
From source file:info.guardianproject.gpg.FileDialogFragment.java
/** * Send message back to handler which is initialized in a activity * /*from w ww. j ava 2 s .com*/ * @param what Message integer you want to send */ private void sendMessageToHandler(Integer what, Bundle data) { Message msg = Message.obtain(); msg.what = what; if (data != null) { msg.setData(data); } try { mMessenger.send(msg); } catch (RemoteException e) { Log.w(TAG, "Exception sending message, Is handler present?", e); } catch (NullPointerException e) { Log.w(TAG, "Messenger is null!", e); } }