List of usage examples for android.os Message obtain
public static Message obtain()
From source file:id.nci.stm_9.SetPassphraseDialogFragment.java
/** * Send message back to handler which is initialized in a activity * //w ww .ja va 2s . 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.abiansoftware.lib.reader.AbianReaderApplication.java
public void sendDataUpdatedMessage() { for (int i = 0; i < m_handlerVector.size(); i++) { Handler thisHandler = m_handlerVector.get(i); if (thisHandler != null) { //thisHandler.sendEmptyMessage(AbianReaderApplication.MSG_DATA_UPDATED); Message newMessage = Message.obtain(); newMessage.what = AbianReaderApplication.MSG_DATA_UPDATED; thisHandler.sendMessageAtFrontOfQueue(newMessage); }// w w w . j ava 2s .co m } /* for(int i = 0; i < m_adapterVector.size(); i++) { BaseAdapter thisAdapter = m_adapterVector.get(i); if(thisAdapter != null) { //thisAdapter.notifyDataSetChanged(); } } */ }
From source file:com.twinflag.coofiletouch.AuthorityChecking.java
private void fetchLicenseFromInternet() { Log.i(TAG, "===fetchLicenseFromInternet !"); new Thread() { public void run() { try { JSONObject json = new JSONObject(); try { int readLength = 0; int sendSize = 0; json.put("command", "checkLicense"); json.put("hardinfo", DeviceUtil.getDeviceInfo()); Socket socket = new Socket("192.168.13.95", 60000); // ? OutputStream os = socket.getOutputStream(); String jsonStr = json.toString(); byte[] buffer = jsonStr.getBytes("UTF-8"); sendSize = buffer.length; byte[] array = new byte[4]; array[3] = (byte) (0xff & sendSize); array[2] = (byte) ((0xff00 & sendSize) >> 8); array[1] = (byte) ((0xff0000 & sendSize) >> 16); array[0] = (byte) (0xff000000 & sendSize >> 24); os.write(array);/*from w w w .j a v a 2 s. c o m*/ os.flush(); os.write(buffer); os.flush(); // ; InputStream inputStream = socket.getInputStream(); byte[] length = new byte[4]; byte[] temp = new byte[4]; byte oneByte; try { inputStream.read(length); } catch (IOException e1) { e1.printStackTrace(); } for (int i = 0; i < 4; i++) { temp[3 - i] = length[i]; } for (int j = 0; j < 4; j++) { oneByte = temp[j]; readLength += (oneByte & 0xFF) << (8 * j); } System.out.println(readLength + "?"); if (readLength == 0) { System.out.println("readLength == 0"); Message msg = Message.obtain(); msg.what = MSG_GET_LINCENSE_FROM_INTERNET; msg.obj = null; mHandler.sendMessageDelayed(msg, 100); } // ??0 else { System.out.println("readLength == " + readLength); buffer = new byte[readLength]; try { String receivedContent = null; inputStream.read(buffer, 0, readLength); receivedContent = new String(buffer, "UTF-8"); Message msg = Message.obtain(); msg.what = MSG_GET_LINCENSE_FROM_INTERNET; msg.obj = receivedContent; mHandler.sendMessageDelayed(msg, 100); } catch (IOException e) { e.printStackTrace(); } } socket.close(); } catch (JSONException exception) { exception.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } } }.start(); }
From source file:com.jwork.spycamera.CameraTaskService.java
private void startFaceShot() { CameraTaskService.setState(WHAT_START_FACESHOT); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, createStopNotification("Detect")); Message backMsg = Message.obtain(); backMsg.what = MainController.WHAT_START_FACESHOOT; try {//from w ww. j a v a 2 s .c om this.outMessenger.send(backMsg); } catch (android.os.RemoteException e1) { log.w(this, e1); } }
From source file:net.networksaremadeofstring.rhybudd.DiagnosticActivity.java
private void DoDiagnostics() { (new Thread() { Message msg = Message.obtain(); //Bundle bundle = new Bundle(); ZenossAPI API;/* w w w .ja va2s . com*/ SharedPreferences settings; public void run() { msg.what = DIAGNOSTIC_SUCCESS; try { //Lets get started SendUpdate("Getting Zenoss details", DIAGNOSTIC_PRE); //Lets have a look at the preferences settings = PreferenceManager.getDefaultSharedPreferences(DiagnosticActivity.this); ZenossCredentials credentials = new ZenossCredentials(DiagnosticActivity.this); SendUpdate("Credentials object initialized", DIAGNOSTIC_SUCCESS); //Show them their credentials SendUpdate("Auth options;\n" + "\tURL: " + credentials.URL + "\n" + "\tUser: " + credentials.UserName + "\n" + "\tPassword: Not shown", DIAGNOSTIC_PRE); //Sleep============================================================================================================== sleep(1000); SendUpdate("Initialising the Rhybudd API", DIAGNOSTIC_PRE); //Connect to Zenoss if (settings.getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) { SendUpdate("Detected a ZAAS Configuration. Prepping ZaaS API", DIAGNOSTIC_SUCCESS); API = new ZenossAPIZaas(); } else { SendUpdate("Detected a Zenoss Core Configuration. Prepping Core API", DIAGNOSTIC_SUCCESS); API = new ZenossAPICore(); } //Sleep============================================================================================================== sleep(1000); SendUpdate("Attempting to login...", DIAGNOSTIC_PRE); Boolean loginSuccessful = API.Login(credentials); if (loginSuccessful) { SendUpdate("Login appeared to be successful.", DIAGNOSTIC_SUCCESS); SendUpdate("Getting a list of Events based on your settings via the Rhybudd API", DIAGNOSTIC_PRE); List<ZenossEvent> listOfZenossEvents = new ArrayList<ZenossEvent>(); //Sleep============================================================================================================== sleep(1000); listOfZenossEvents = API.GetRhybuddEvents(DiagnosticActivity.this); try { //Sleep============================================================================================================== sleep(1000); if (listOfZenossEvents.size() > 0) { SendUpdate("We successfully got a list of events through the API interface!", DIAGNOSTIC_SUCCESS); } else { SendUpdate("We successfully queried Zenoss but got no devices back", DIAGNOSTIC_SUCCESS); } } catch (NullPointerException npe) { //Sleep============================================================================================================== sleep(1000); SendUpdate("We received null back which indicates an internal issue.", DIAGNOSTIC_SUCCESS); } //Sleep============================================================================================================== sleep(1000); SendUpdate( "Performing a manual query (not using the Rhybudd API) with very permissive filters (e.g. all Production states, all severities) without #ZEN-2812 fix", DIAGNOSTIC_PRE); try { //Sleep============================================================================================================== sleep(1000); String eventsRawJSON = DoRawQuery(false); SendUpdate("We received a payload from the query.", DIAGNOSTIC_SUCCESS); if (null != eventsRawJSON) { SendUpdate("Attemping to convert payload to JSON", DIAGNOSTIC_PRE); try { JSONObject json = new JSONObject(eventsRawJSON); if (json instanceof JSONObject) { SendUpdate("The Payload successfully parsed as JSON full payload was;\n\n" + json.toString(3), DIAGNOSTIC_SUCCESS); } else { SendUpdate( "The data returned from the query wasn't valid. Attempting to display:", DIAGNOSTIC_FAILURE); SendUpdate("\t" + eventsRawJSON, DIAGNOSTIC_FAILURE); } } catch (Exception e) { SendUpdate(e.getMessage(), DIAGNOSTIC_FAILURE); } } else { SendUpdate("We received null back which indicates an issue but not an exception.", DIAGNOSTIC_SUCCESS); } } catch (Exception e) { //Sleep============================================================================================================== sleep(1000); SendUpdate("There was an exception;\n" + e.getMessage(), DIAGNOSTIC_SUCCESS); //Sleep============================================================================================================== sleep(500); SendUpdate("Trying a query with the fix for #ZEN-2812", DIAGNOSTIC_SUCCESS); DoRawQuery(true); } //Sleep============================================================================================================== sleep(1000); //--------------------------------------------------------------------------------------------------------------------------------------------------------- // And we're done! //--------------------------------------------------------------------------------------------------------------------------------------------------------- SendUpdate("Still here? Awesome.\n\n\nAll tests appear to have passed.", DIAGNOSTIC_COMPLETE); } else { SendUpdate("Login Failed.\n\nMessage was: " + API.getLastException(), DIAGNOSTIC_FAILURE); } } catch (Exception e) { SendUpdate(e.getMessage(), DIAGNOSTIC_FAILURE); } } private String DoRawQuery(boolean Zenoss41) throws Exception { HttpPost httpost = new HttpPost(API.ZENOSS_INSTANCE + "/zport/dmd/Events/evconsole_router"); httpost.addHeader("Content-type", "application/json; charset=utf-8"); httpost.setHeader("Accept", "application/json"); JSONObject dataContents = new JSONObject(); dataContents.put("start", 0); dataContents.put("limit", 10); dataContents.put("dir", "DESC"); dataContents.put("sort", "severity"); if (Zenoss41) { dataContents.put("keys", new JSONArray( "[evid,count,prodState,firstTime,severity,component,summary,eventState,device,eventClass,lastTime,ownerid]")); } JSONObject params = new JSONObject(); params.put("severity", new JSONArray("[5,4,3,2]")); params.put("eventState", new JSONArray("[0, 1]")); /*if(null != SummaryFilter && !SummaryFilter.equals("")) { params.put("summary", SummaryFilter); }*/ /*if(null != DeviceFilter && !DeviceFilter.equals("")) { params.put("device", DeviceFilter); }*/ /*if(ProductionOnly) { params.put("prodState", new JSONArray("[1000]")); }*/ dataContents.put("params", params); JSONArray data = new JSONArray(); data.put(dataContents); JSONObject reqData = new JSONObject(); reqData.put("action", "EventsRouter"); reqData.put("method", "query"); reqData.put("data", data); reqData.put("type", "rpc"); reqData.put("tid", String.valueOf(API.reqCount++)); httpost.setEntity(new StringEntity(reqData.toString())); HttpResponse response = API.httpclient.execute(httpost); String eventsRawJSON = EntityUtils.toString(response.getEntity()); response.getEntity().consumeContent(); //JSONObject json = new JSONObject(eventsRawJSON); return eventsRawJSON; } private void SendUpdate(String Message, int What) { msg = progressHandler.obtainMessage(What); //msg.what = What; Bundle bundle = new Bundle(); bundle.putString(DIAGNOSTIC_OUTPUT, Message); msg.setData(bundle); progressHandler.sendMessage(msg); } }).start(); }
From source file:org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity.java
private void sendMessage(int what) { if (mMessenger != null) { Message msg = Message.obtain(); msg.what = what;/* www . j a v a 2s.c om*/ try { mMessenger.send(msg); } catch (RemoteException e) { Log.e(Constants.TAG, "Could not deliver message", e); } } }
From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java
public void editpaypassword(final String phone, final String code, final String password) { new Thread() { Message msg = Message.obtain(); public void run() { String data = "&phone=" + phone + "&code=" + code + "&password=" + password; Log.e("data is ", data); String result_data = NetUtil.getResponse(WebAddress.UPDATEPAYPASSWORD, data); Log.e("successful", result_data); try { JSONObject obj = new JSONObject(result_data); msg.what = CommunalInterfaces.UpdatePayPass; msg.obj = obj;/*w w w . j av a 2s . co m*/ } catch (JSONException e) { e.printStackTrace(); } finally { handler.sendMessage(msg); } } }.start(); }
From source file:info.guardianproject.gpg.FileDialogFragment.java
/** * Send message back to handler which is initialized in a activity * /*from w w w.j ava2 s. 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(TAG, "Exception sending message, Is handler present?", e); } catch (NullPointerException e) { Log.w(TAG, "Messenger is null!", e); } }
From source file:org.sufficientlysecure.keychain.ui.dialog.AddEmailDialogFragment.java
/** * Send message back to handler which is initialized in a activity * * @param what Message integer you want to send *///from w w w . java2 s .c om private void sendMessageToHandler(Integer what) { Message msg = Message.obtain(); msg.what = what; try { mMessenger.send(msg); } catch (RemoteException e) { Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); } catch (NullPointerException e) { Log.w(Constants.TAG, "Messenger is null!", e); } }
From source file:com.darshancomputing.BatteryIndicatorPro.PersistentFragment.java
public void sendServiceMessage(int what) { if (serviceMessenger == null) return;// ww w . ja v a2 s . c o m Message outgoing = Message.obtain(); outgoing.what = what; outgoing.replyTo = messenger; try { serviceMessenger.send(outgoing); } catch (android.os.RemoteException e) { } }