List of usage examples for android.os Message setData
public void setData(Bundle data)
From source file:org.ntpsync.service.NtpSyncService.java
@Override protected void onHandleIntent(Intent intent) { // lock cpu/*from ww w . j a va2 s .co m*/ getLocks(this); lock(); Bundle extras = intent.getExtras(); if (extras == null) { Log.e(Constants.TAG, "Extra bundle is null!"); return; } // fail if required keys are not present if (!extras.containsKey(EXTRA_ACTION)) { Log.e(Constants.TAG, "Extra bundle must contain a action!"); return; } int action = extras.getInt(EXTRA_ACTION); // for these actions we get a result back which is send via the messenger and we require // a data bundle if (!(extras.containsKey(EXTRA_DATA))) { Log.e(Constants.TAG, "Extra bundle must contain a data bundle!"); return; } else { mData = extras.getBundle(EXTRA_DATA); } boolean noMessenger = false; if (!(extras.containsKey(EXTRA_MESSENGER))) { Log.e(Constants.TAG, "No messenger present, using default result handling!"); noMessenger = true; } else { mMessenger = (Messenger) extras.get(EXTRA_MESSENGER); } // get NTP server from preferences String ntpHostname = PreferenceHelper.getNtpServer(this); // default values int returnMessage = RETURN_GENERIC_ERROR; long offset = 0; // execute action from extra bundle switch (action) { case ACTION_QUERY: // return time to ui Bundle messageData = new Bundle(); try { offset = NtpSyncUtils.query(ntpHostname); returnMessage = RETURN_OKAY; // calculate new time Date newTime = new Date(System.currentTimeMillis() + offset); messageData.putSerializable(MESSAGE_DATA_TIME, newTime); if (mData.containsKey(DATA_APPLY_DIRECTLY)) { if (mData.getBoolean(DATA_APPLY_DIRECTLY)) { returnMessage = Utils.setTime(offset); } } } catch (IOException e) { returnMessage = RETURN_SERVER_TIMEOUT; Log.d(Constants.TAG, "Timeout on server!"); } if (noMessenger && PreferenceHelper.getShowSyncToast(this)) { Message msg = Message.obtain(); msg.arg1 = returnMessage; msg.setData(messageData); handleResult(msg); } else { sendMessageToHandler(returnMessage, messageData); } break; case ACTION_QUERY_DETAILED: String output = null; Bundle messageDataDetailedQuery = null; try { TimeInfo info = NtpSyncUtils.detailedQuery(ntpHostname); output = NtpSyncUtils.processResponse(info, this); // return detailed output to ui messageDataDetailedQuery = new Bundle(); messageDataDetailedQuery.putSerializable(MESSAGE_DATA_DETAILED_OUTPUT, output); returnMessage = RETURN_OKAY; } catch (IOException e) { returnMessage = RETURN_SERVER_TIMEOUT; Log.d(Constants.TAG, "Timeout on server!"); } if (noMessenger && PreferenceHelper.getShowSyncToast(this)) { Message msg = Message.obtain(); msg.arg1 = returnMessage; msg.setData(messageDataDetailedQuery); handleResult(msg); } else { sendMessageToHandler(returnMessage, messageDataDetailedQuery); } break; default: break; } // unlock cpu unlock(); }
From source file:net.networksaremadeofstring.rhybudd.ZaasSettingsFragment.java
private void UpdateDebugMessage(String Message) { android.os.Message msg = new Message(); Bundle bundle = new Bundle(); msg.what = RhybuddHandlers.msg_initial_verify_debug_output; bundle.putString(ZenossAPI.MSG_DEBUG, Message); msg.setData(bundle); handler.sendMessage(msg);//from ww w . j a v a 2 s. co m }
From source file:com.grass.caishi.cc.service.BaseIntentService.java
/** * You should not override this method for your IntentService. Instead, * override {@link #onHandleIntent}, which the system calls when the * IntentService receives a start request. * /*from w w w. j a va 2 s. c o m*/ * @see android.app.Service#onStartCommand */ @Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { int ddo = intent.getIntExtra("do", 0); if (ddo != 0) { SendBean send = (SendBean) intent.getSerializableExtra("send"); Message msg = mServiceHandler.obtainMessage(); msg.arg1 = send.getSend_id(); msg.what = send.getSend_id(); Bundle b = new Bundle(); b.putSerializable("send", send); msg.setData(b); // filelist.add(send); mServiceHandler.sendMessage(msg); intent.putExtra("do", UP_ADD); sendBroadcast(intent); } } return START_NOT_STICKY; }
From source file:net.networksaremadeofstring.rhybudd.CoreSettingsFragment.java
private void UpdateDebugMessage(String Message) { Message msg = new Message(); Bundle bundle = new Bundle(); msg.what = RhybuddHandlers.msg_initial_verify_debug_output; bundle.putString(ZenossAPI.MSG_DEBUG, Message); msg.setData(bundle); handler.sendMessage(msg);//from w w w . jav a2 s .c o m }
From source file:org.runbuddy.tomahawk.mediaplayers.PluginMediaPlayer.java
protected synchronized void callService(int what, Bundle bundle) { Message message = Message.obtain(null, what); message.setData(bundle); callService(message);/*from w w w .j av a 2s .c o m*/ }
From source file:org.sufficientlysecure.keychain.ui.dialog.AddEditKeyserverDialogFragment.java
/** * Send message back to handler which is initialized in a activity * * @param what Message integer you want to send *//*from w w w . j a v a 2 s . c om*/ 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(Constants.TAG, "Exception sending message, Is handler present?", e); } catch (NullPointerException e) { Log.w(Constants.TAG, "Messenger is null!", e); } }
From source file:com.emorym.android_pusher.Pusher.java
public void connect() { String prefix = mEncrypted ? HTTPS_PREFIX : HTTP_PREFIX; int port = mEncrypted ? WSS_PORT : WS_PORT; String path = "/app/" + mApplicationkey + "?client=js&version=" + VERSION; try {/*from w w w .j a v a 2 s . c o m*/ URI url = new URI(prefix + HOST + ":" + port + path); if (Log.isLoggable(TAG, DEBUG)) Log.d(TAG, "Connecting to: " + url.toString()); mWebSocket = new WebSocketConnection(url); mWebSocket.setTrustAllCerts(trustAllCerts); mWebSocket.setEventHandler(new WebSocketEventHandler() { public void onOpen() { if (Log.isLoggable(TAG, DEBUG)) Log.d(TAG, "WebSocket Open"); subscribeToAllChannels(); } public void onMessage(WebSocketMessage message) { try { if (Log.isLoggable(TAG, DEBUG)) Log.d(TAG, "Message: " + message.getText()); JSONObject jsonMessage = new JSONObject(message.getText()); String event = jsonMessage.optString("event", null); if (event.equals("pusher:connection_established")) { JSONObject data = new JSONObject(jsonMessage.getString("data")); mSocketId = data.getString("socket_id"); if (Log.isLoggable(TAG, DEBUG)) Log.d(TAG, "Connection Established with Socket Id: " + mSocketId); } else { Bundle b = new Bundle(); b.putString("event", event); b.putString("data", jsonMessage.getString("data")); // backwards compatibility b.putString("type", "pusher"); b.putString("message", message.getText()); if (jsonMessage.has("channel")) { b.putString("channel", jsonMessage.getString("channel")); } Message msg = new Message(); msg.setData(b); mHandler.sendMessage(msg); } } catch (JSONException e) { if (Log.isLoggable(TAG, DEBUG)) Log.d(TAG, "JSON exception", e); } } public void onClose() { if (Log.isLoggable(TAG, DEBUG)) Log.d(TAG, "WebSocket Closed"); } }); mWatchdog = new Thread(new Runnable() { public void run() { boolean interrupted = false; while (!interrupted) { try { Thread.sleep(WATCHDOG_SLEEP_TIME_MS); if (!mWebSocket.isConnected()) mWebSocket.connect(); } catch (InterruptedException e) { interrupted = true; } catch (Exception e) { if (Log.isLoggable(TAG, DEBUG)) Log.d(TAG, "Exception connecting", e); } } } }); mWatchdog.start(); } catch (WebSocketException e) { if (Log.isLoggable(TAG, DEBUG)) Log.d(TAG, "Web socket exception", e); } catch (URISyntaxException e) { if (Log.isLoggable(TAG, DEBUG)) Log.d(TAG, "URI syntax exception", e); } }
From source file:com.open.file.manager.CutCopyService.java
void sendDuplicateMessage() { Message dupmsg = Message.obtain(); dupmsg.what = Consts.MSG_DUPLICATES; Bundle dupdata = new Bundle(); dupdata.putParcelableArrayList("duplicates", tree.duplicates); dupmsg.setData(dupdata); MainActivity.acthandler.sendMessage(dupmsg); }
From source file:com.marianhello.bgloc.LocationService.java
public void handleError(JSONObject error) { Bundle bundle = new Bundle(); bundle.putString("error", error.toString()); Message msg = Message.obtain(null, MSG_ERROR); msg.setData(bundle); sendClientMessage(msg);//from w w w . j ava2s. co m }
From source file:tw.jwzhuang.ipcamviewer.devices.CaptureActivity.java
private void add(final String contents) { try {/*from ww w.ja v a 2s .c om*/ JSONObject jobj = new JSONObject(contents); Bundle data = new Bundle(); data.putString("pwd", jobj.getString("pwd")); data.putString("ip", jobj.getString("ip")); Message message = Message.obtain(); message.what = handler.ASKADD; message.setData(data); handler.sendMessage(message); } catch (JSONException e) { restartPreviewAfterDelay(0L); } }