Example usage for android.os Message setData

List of usage examples for android.os Message setData

Introduction

In this page you can find the example usage for android.os Message setData.

Prototype

public void setData(Bundle data) 

Source Link

Document

Sets a Bundle of arbitrary data values.

Usage

From source file:thproject.test.com.myapplication.SongRecognitionActivity.java

public static void progressText(String a) {
    Message msg = new Message();
    Bundle data = new Bundle();
    data.putString("action", "progresstext");
    data.putString("text", a);
    msg.setData(data);
    handler.sendMessage(msg);//from w  ww .  jav  a  2  s . com
}

From source file:Main.java

public static ResponseHandler<String> GetResponseHandlerInstance(final Handler handler) {
    final ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
        @Override/* ww w .jav  a 2s  . c  om*/
        public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            Message message = handler.obtainMessage();
            Bundle bundle = new Bundle();
            StatusLine status = response.getStatusLine();
            HttpEntity entity = response.getEntity();
            String result = null;
            if (entity != null) {
                try {
                    result = InputStreamToString(entity.getContent());
                    bundle.putString("RESPONSE", result);
                    message.setData(bundle);
                    handler.sendMessage(message);
                } catch (IOException e) {
                    bundle.putString("RESPONSE", "Error - " + e.getMessage());
                    message.setData(bundle);
                    handler.sendMessage(message);
                }
            } else {
                bundle.putString("RESPONSE", "Error - " + response.getStatusLine().getReasonPhrase());
                message.setData(bundle);
                handler.sendMessage(message);
            }
            return result;
        }
    };

    return responseHandler;
}

From source file:by.zatta.pilight.connection.ConnectionService.java

/**
 * Send the data to all clients./*w ww. j  a v  a2  s .  c  om*/
 * 
 * @param message
 *            The message to send.
 */
private static void sendMessageToUI(int what, String message) {
    // Log.v(TAG, "sent message called, clients attached: " + Integer.toString(mClients.size()));
    Iterator<Messenger> messengerIterator = mClients.iterator();
    while (messengerIterator.hasNext()) {
        Messenger messenger = messengerIterator.next();
        try {
            Bundle bundle = new Bundle();
            bundle.setClassLoader(aCtx.getClassLoader());
            switch (what) {
            case MSG_SET_STATUS:
                // Log.v(TAG, "setting status: " + message);
                bundle.putString("status", message);
                Message msg_string = Message.obtain(null, MSG_SET_STATUS);
                msg_string.setData(bundle);
                messenger.send(msg_string);
                break;
            case MSG_SET_BUNDLE:
                if (!mDevices.isEmpty()) {
                    // Log.v(TAG, "putting mDevices");
                    bundle.putParcelableArrayList("config", (ArrayList<? extends Parcelable>) mDevices);
                    Message msg = Message.obtain(null, MSG_SET_BUNDLE);
                    msg.setData(bundle);
                    messenger.send(msg);
                }
                break;
            }
        } catch (RemoteException e) {
            Log.w(TAG, "mClients.remove called");
            mClients.remove(messenger);
        }
    }
}

From source file:thproject.test.com.myapplication.SongRecognitionActivity.java

public static void loopToast(String a, String b) {
    Message msg = new Message();
    Bundle data = new Bundle();

    data.putString("action", "test");
    data.putString("artist", a);
    data.putString("album", b);

    msg.setData(data);
    handler.sendMessage(msg);//from w ww .  ja va 2 s .  co  m
}

From source file:com.max2idea.android.fwknop.Fwknop.java

public static void sendHandlerMessage(Handler handler, int message_type) {
    Message msg1 = handler.obtainMessage();
    Bundle b = new Bundle();
    b.putInt("message_type", message_type);
    msg1.setData(b);
    handler.sendMessage(msg1);//from ww w .j a  va2  s .c om
}

From source file:com.max2idea.android.fwknop.Fwknop.java

public static void sendHandlerMessage(Handler handler, int message_type, String message_var,
        String message_value) {/*from   w  ww.  j av a  2s .c  om*/
    Message msg1 = handler.obtainMessage();
    Bundle b = new Bundle();
    b.putInt("message_type", message_type);
    b.putString(message_var, message_value);
    msg1.setData(b);
    handler.sendMessage(msg1);
}

From source file:android.support.v7.media.MediaRouteProviderService.java

static void sendReply(Messenger messenger, int what, int requestId, int arg, Object obj, Bundle data) {
    Message msg = Message.obtain();
    msg.what = what;// w  ww . jav  a 2 s  . com
    msg.arg1 = requestId;
    msg.arg2 = arg;
    msg.obj = obj;
    msg.setData(data);
    try {
        messenger.send(msg);
    } catch (DeadObjectException ex) {
        // The client died.
    } catch (RemoteException ex) {
        Log.e(TAG, "Could not send message to " + getClientId(messenger), ex);
    }
}

From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java

public static Message JSONtoUserDataMessage(JsonNode result, UserData userData) {
    Message ret = new Message();
    Bundle data = new Bundle();
    if (result != null) {
        data.putBoolean("success", result.get("success").asBoolean());
        data.putString("info", result.get("info").asText());
        JsonNode dataNode = result.get("data");
        if (dataNode != null) {
            data.putInt("id", dataNode.get("id").asInt());
            data.putString("name", dataNode.get("name").asText());
            data.putString("email", dataNode.get("email").asText());
            if (dataNode.has("image_url"))
                data.putString("image_url", dataNode.get("image_url").asText());
        }//from  w ww .  ja va  2  s.c o m
        ret.setData(data);
    }
    return ret;
}

From source file:ee.ioc.phon.android.speak.RecognizerIntentActivity.java

private static Message createMessage(int type, String str) {
    Bundle b = new Bundle();
    b.putString(MSG, str);//from   www.j ava 2 s . co  m
    Message msg = Message.obtain();
    msg.what = type;
    msg.setData(b);
    return msg;
}

From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java

public static Message JSONtoMessage(JsonNode result) {
    Message ret = new Message();
    Bundle data = new Bundle();
    if (result != null) {
        data.putBoolean("success", result.get("success").asBoolean());
        data.putString("info", result.get("info").asText());
        if (result.has("errors"))
            data.putString("errors", result.get("errors").asText());
        JsonNode dataNode = result.get("data");
        if (dataNode != null) {
            if (dataNode.has("id"))
                data.putInt("id", dataNode.get("id").asInt());
            if (dataNode.has("auth_token"))
                data.putString("auth_token", dataNode.get("auth_token").asText());
        }//  w ww.  j a  v  a  2 s  .  co m
    }
    ret.setData(data);
    return ret;
}