List of usage examples for android.os Message setData
public void setData(Bundle data)
From source file:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java
/** * @see BluetoothHeadsetMonitor.BluetoothHeadsetMonitorDelegate#onHeadsetConnected(String) * *///from w w w . j a va 2s. c om @Override public void onHeadsetConnected(String name) { if (mCallbackMessengers.isEmpty()) { // final Intent notificationIntent = new Intent(this, MainActivity.class); final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.headset_launcher_notification).setContentTitle(name) .setContentText(getString(R.string.text_headset_connected)).setContentIntent(contentIntent) .setAutoCancel(true); final NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(1, builder.build()); // ? ? ? mTimer.start(); } else { // final Bundle data = new Bundle(); data.putString("ConnectedHeadsetName", name); for (Messenger x : mCallbackMessengers) { try { final Message message = Message.obtain(null, 3, 0, 0); message.setData(data); x.send(message); } catch (RemoteException e) { Log.e(TAG, "Callback error!"); } } } }
From source file:com.marianhello.bgloc.LocationService.java
public void handleStationary(BackgroundLocation location) { log.debug("New stationary {}", location.toString()); Bundle bundle = new Bundle(); bundle.putParcelable("location", location); Message msg = Message.obtain(null, MSG_ON_STATIONARY); msg.setData(bundle); sendClientMessage(msg);/*from w ww .j a va 2 s .c o m*/ }
From source file:org.navitproject.navit.NavitDownloadSelectMapActivity.java
private void askForMapDeletion(final String map_location) { AlertDialog.Builder deleteMapBox = new AlertDialog.Builder(this); deleteMapBox.setTitle(Navit.getInstance().getTstring(R.string.map_delete)); deleteMapBox.setCancelable(true);/*from ww w. java 2 s .c o m*/ NavitMap maptoDelete = new NavitMap(map_location); deleteMapBox .setMessage(maptoDelete.mapName + " " + String.valueOf(maptoDelete.size() / 1024 / 1024) + "MB"); // TRANS deleteMapBox.setPositiveButton(Navit.getInstance().getTstring(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { Log.d(TAG, "Delete Map"); Message msg = Message.obtain(Navit.getInstance().getNavitGraphics().callback_handler, NavitGraphics.msg_type.CLB_DELETE_MAP.ordinal()); Bundle b = new Bundle(); b.putString("title", map_location); msg.setData(b); msg.sendToTarget(); finish(); } }); // TRANS deleteMapBox.setNegativeButton((Navit.getInstance().getTstring(R.string.no)), new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { Log.d(TAG, "don't delete map"); } }); deleteMapBox.show(); }
From source file:com.noah.lol.network.RequestNetwork.java
protected void asyncRequestGet(final String url, final NetworkListener<String> listener) { if (url == null) { return;//from ww w. ja va2 s. c o m } try { environmentCheck(); } catch (EnvironmentException e) { if (listener != null) { e.setStatus(BAD_REQUEST_ENVIRONMENT_CONFIG); listener.onNetworkFail(BAD_REQUEST_ENVIRONMENT_CONFIG, e); } return; } final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { Bundle bundle = msg.getData(); switch (msg.what) { case REQUEST_SUCCESS: String responseBody = bundle.getString(RESPONSE_KEY); if (listener != null && responseBody != null) { listener.onSuccess(responseBody); } break; case REQUEST_FAIL: NetworkException e = (NetworkException) bundle.getSerializable(EXCEPTION_KEY); if (listener != null) { listener.onNetworkFail(e.getStatus(), e); } break; } } }; new Thread(new Runnable() { @Override public void run() { String responseBody = null; Message message = new Message(); try { responseBody = syncRequestGet(url); Bundle bundle = new Bundle(); bundle.putString(RESPONSE_KEY, responseBody); message = Message.obtain(handler, REQUEST_SUCCESS); message.setData(bundle); handler.sendMessage(message); } catch (NetworkException e) { Bundle bundle = new Bundle(); bundle.putSerializable(EXCEPTION_KEY, e); message = Message.obtain(handler, REQUEST_FAIL); message.setData(bundle); handler.sendMessage(message); e.printStackTrace(); } } }).start(); }
From source file:com.samsung.smcl.example.helloworldprovider.backend.HelloWorldProviderService.java
private boolean sendToHelloWorldService(String data) { if (mHelloWorldMessenger == null || mBound == false) { Utility.logError(TAG, "mHelloWorldMessenger is null or mBound is false, return false"); return false; }//from w ww . jav a 2 s. c om Bundle providerData = new Bundle(1); providerData.putString(BUNDLE_DATA, data); Message providerMsg = Message.obtain(null, MSG_TO_HELLOWORLDSERVICE, 0, 0); providerMsg.setData(providerData); try { mHelloWorldMessenger.send(providerMsg); Utility.logDebug(TAG, "MSG_TO_HELLOWORLDSERVICE"); } catch (RemoteException e) { Utility.logError(TAG, "", e); return false; } return true; }
From source file:com.marianhello.bgloc.LocationService.java
/** * Handle location from location location provider * * All locations updates are recorded in local db at all times. * Also location is also send to all messenger clients. * * If option.url is defined, each location is also immediately posted. * If post is successful, the location is deleted from local db. * All failed to post locations are coalesced and send in some time later in one single batch. * Batch sync takes place only when number of failed to post locations reaches syncTreshold. * * If only option.syncUrl is defined, locations are send only in single batch, * when number of locations reaches syncTreshold. * * @param location/* ww w . j a va2s. c o m*/ */ public void handleLocation(BackgroundLocation location) { log.debug("New location {}", location.toString()); location.setBatchStartMillis(System.currentTimeMillis() + ONE_MINUTE); // prevent sync of not yet posted location persistLocation(location); if (config.hasUrl() || config.hasSyncUrl()) { Long locationsCount = dao.locationsForSyncCount(System.currentTimeMillis()); log.debug("Location to sync: {} threshold: {}", locationsCount, config.getSyncThreshold()); if (locationsCount >= config.getSyncThreshold()) { log.debug("Attempt to sync locations: {} threshold: {}", locationsCount, config.getSyncThreshold()); SyncService.sync(syncAccount, getStringResource(Config.CONTENT_AUTHORITY_RESOURCE)); } } if (hasConnectivity && config.hasUrl()) { postLocationAsync(location); } Bundle bundle = new Bundle(); bundle.putParcelable("location", location); Message msg = Message.obtain(null, MSG_LOCATION_UPDATE); msg.setData(bundle); sendClientMessage(msg); }
From source file:com.DGSD.DGUtils.ImageDownloader.ImageLoader.java
public void notifyImageLoaded(String url, Bitmap bitmap) { Message message = new Message(); message.what = HANDLER_MESSAGE_ID;/* w w w .ja v a2 s.c om*/ Bundle data = new Bundle(); data.putString(IMAGE_URL_EXTRA, url); Bitmap image = bitmap; data.putParcelable(BITMAP_EXTRA, image); message.setData(data); handler.sendMessage(message); }
From source file:com.funambol.android.controller.AndroidRegisterScreenController.java
public void performRegReq() { final ResponseHandler<String> responseHandler = new ResponseHandler<String>() { public String handleResponse(HttpResponse response) { StatusLine status = response.getStatusLine(); HttpEntity entity = response.getEntity(); String result = null; try { InputStream is = entity.getContent(); BufferedReader r = new BufferedReader(new InputStreamReader(is)); StringBuilder total = new StringBuilder(); String line;//from w w w. j av a 2 s .c o m while ((line = r.readLine()) != null) { total.append(line); } result = total.substring(3); //TODO: magic num. 3 elements before the readable value, WHY??? Message message = handler.obtainMessage(); Bundle bundle = new Bundle(); bundle.putString("RESPONSE", result); message.setData(bundle); handler.sendMessage(message); } catch (IOException e) { Log.debug(TAG_LOG, e.toString()); } return result; } }; spinnerTriggerUIThread.setValue(true); spinnerTriggerUIThread.setMessage(localization.getLanguage("signup_please_wait")); screen.runOnUiThread(spinnerTriggerUIThread); new Thread() { public void run() { try { DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(RegCgiUri); // List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("username", screen.getUsername())); nameValuePairs.add(new BasicNameValuePair("password", screen.getPassword())); nameValuePairs.add(new BasicNameValuePair("confirm_pwd", screen.getConfirmPassword())); nameValuePairs.add(new BasicNameValuePair("phone", screen.getPhoneNumber())); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); client.execute(post, responseHandler); } catch (ClientProtocolException e) { Log.debug(TAG_LOG, e.toString()); } catch (IOException e) { Log.debug(TAG_LOG, e.toString()); } } }.start(); }
From source file:org.wahtod.wififixer.ui.MainActivity.java
private void bundleIntent(Intent intent) { /*/* www. j a v a 2 s . c om*/ * Dispatch intent commands to handler */ Message message = handler.obtainMessage(); Bundle data = new Bundle(); data.putString(PrefUtil.INTENT_ACTION, intent.getAction()); if (intent.getExtras() != null) { data.putAll(intent.getExtras()); } message.setData(data); handler.sendMessage(message); }
From source file:fr.mixit.android.ui.fragments.MyPlanningFragment.java
protected void getStarredSessions(int memberId) { if (mIsBound && mServiceReady) { final Message msg = Message.obtain(null, MixItService.MSG_GET_STARRED_SESSION, 0, 0); msg.replyTo = mMessenger;/*from w ww . ja v a2 s .c o m*/ final Bundle b = new Bundle(); b.putInt(MixItService.EXTRA_MEMBER_ID, memberId); msg.setData(b); try { mService.send(msg); setRefreshMode(true); } catch (final RemoteException e) { e.printStackTrace(); } } }