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:com.example.helloworldlinked.backend.HelloWorldService.java

public void sendAccessoryNotificationMessage(NotificationModel notification) {
    if (notification == null) {
        Utility.logWarning(TAG, "Not sending null notification");
        return;//from  www.j av a  2 s . c om
    }
    Message message = Message.obtain(null, MSG_NOTIFICATION);
    Bundle bundle = notification.createBundle();
    message.setData(bundle);
    sendToProviderService(message);
}

From source file:fr.mixit.android.ui.HomeActivity.java

protected void init() {
    if (mIsBound && mIsServiceReady) {
        final Message msg = Message.obtain(null, MixItService.MSG_INIT, 0, 0);
        msg.replyTo = mMessenger;//w ww . j  a va  2 s.co m
        final Bundle b = new Bundle();
        msg.setData(b);
        try {
            mService.send(msg);
            setRefreshMode(true);
            if (!mIsFirstInitDone) {
                showProgress();
            }

        } catch (final RemoteException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.emorym.android_pusher.PusherChannel.java

public void dispatchEvents(String eventName, String eventData) {
    if (this.isPresence()) {
        if (eventName.equalsIgnoreCase("pusher_internal:subscription_succeeded")) {
            JSONArray users = null;//w  w w.ja v a2  s . co  m
            try {
                users = new JSONArray(eventData);
            } catch (JSONException e) {
                users = new JSONArray();
                //e.printStackTrace();
            }
            for (int i = 0; i < users.length(); i++) {
                try {
                    JSONObject user = users.getJSONObject(i);
                    String user_id = user.getString("user_id");
                    Map<String, String> user_info_map = new HashMap<String, String>();
                    //user_info_map.put("user_id", user_id);

                    if (user.has("user_info")) {
                        JSONObject user_info_json = user.getJSONObject("user_info");
                        Iterator<String> iter = (Iterator<String>) user_info_json.keys();
                        while (iter.hasNext()) {
                            String key = iter.next();
                            String value;
                            try {
                                value = user_info_json.getString(key);
                                user_info_map.put(key, value);
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
                    this.mLocalUsers.put(user_id, user_info_map);

                } catch (JSONException e) {
                    //e.printStackTrace();
                }
            }
        }
        if (eventName.equalsIgnoreCase("pusher_internal:member_added")) {
            JSONObject user = null;
            try {
                user = new JSONObject(eventData);
                String user_id = user.getString("user_id");
                JSONObject user_info_json = user.getJSONObject("user_info");
                Map<String, String> user_info_map = new HashMap<String, String>();
                //user_info_map.put("user_id", user_id);
                Iterator<String> iter = (Iterator<String>) user_info_json.keys();
                while (iter.hasNext()) {
                    String key = iter.next();
                    String value;
                    try {
                        value = user_info_json.getString(key);
                        user_info_map.put(key, value);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                this.mLocalUsers.put(user_id, user_info_map);
            } catch (JSONException e) {
                //e.printStackTrace();
            }

        }
        if (eventName.equalsIgnoreCase("pusher_internal:member_removed")) {
            JSONObject user = null;
            try {
                user = new JSONObject(eventData);
                this.mLocalUsers.remove(user.getString("user_id"));
            } catch (JSONException e) {
                //e.printStackTrace();
            }
        }
    }

    Bundle payload = new Bundle();
    payload.putString("eventName", eventName);
    payload.putString("eventData", eventData);
    payload.putString("channelName", mName);

    Message msg = Message.obtain();
    msg.setData(payload);

    for (PusherCallback callback : mGlobalCallbacks) {
        callback.sendMessage(msg);
    }

    /* do we have a callback bound to that event? */
    if (mLocalCallbacks.containsKey(eventName)) {
        /* execute each callback */
        for (PusherCallback callback : mLocalCallbacks.get(eventName)) {
            callback.sendMessage(msg);
        }
    }
}

From source file:com.nps.micro.UsbService.java

private void sendStatusMessage() {
    for (int i = mClients.size() - 1; i >= 0; i--) {
        try {/*  www.  j a  va2  s . com*/
            Bundle b = new Bundle();
            b.putString(MSG_STATUS_CONTENT, status.getText());
            b.putBoolean(MSG_STATUS_BUSY, status.isBusy());
            Message message = Message.obtain(null, MSG_STATUS);
            message.setData(b);
            mClients.get(i).send(message);

        } catch (RemoteException e) {
            // The client is dead. Remove it from the list; we are going
            // through the list from back to front so this is safe to do
            // inside the loop.
            mClients.remove(i);
        }
    }
}

From source file:com.jackie.movies.ui.DetailActivity.java

private void loadList(String url, final int what, final Class<? extends Parcelable> classOfT) {

    Uri.Builder builder = Uri.parse(url).buildUpon();
    builder.appendQueryParameter(Constants.API_KEY_PARAM, getString(R.string.api_key_v3_auth));
    builder.appendQueryParameter(Constants.LANGUAGE_PARAM, Locale.getDefault().getLanguage());
    url = builder.build().toString();/*  w w w . java 2s .co m*/
    HttpUtils.get(this, url, new HttpUtils.HttpCallBack() {
        @Override
        public void onConnect() {
            Log.d(TAG, "onConnect: ");
        }

        @Override
        public void onCanceled() {
            Log.d(TAG, "onCanceled: ");
        }

        @Override
        public void onSuccess(String response) {
            Log.d(TAG, "onSuccess() called with: response = [" + response + "]");
            Gson gson = new GsonBuilder().create();

            Bundle bundle = new Bundle();
            bundle.putParcelable(EXTRA_ENTITY, gson.fromJson(response, classOfT));

            Message message = new Message();
            message.what = what;
            message.setData(bundle);
            handler.sendMessage(message);
        }

        @Override
        public void onFailure(IOException e) {
            Log.e(TAG, "onFailure: ", e);
        }
    });
}

From source file:org.ntpsync.service.NtpSyncService.java

private void sendMessageToHandler(Integer arg1, Integer arg2, Bundle messageData) {
    Message msg = Message.obtain();
    msg.arg1 = arg1;/*from w w w .j  a v a2  s.c  o  m*/
    if (arg2 != null) {
        msg.arg2 = arg2;
    }
    if (messageData != null) {
        msg.setData(messageData);
    }

    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:cn.sharesdk.analysis.server.ServiceHelper.java

public void saveAndSendLogMsg(Bundle bundle) {
    Message msg = new Message();
    msg.what = SAVE_SEND_LOG;//from w  w  w  .  ja  v  a  2 s.  c om
    msg.setData(bundle);
    handler.sendMessage(msg);
}

From source file:com.tvs.signaltracker.MainScreen.java

private void InitUp() {
    if (CommonHandler.ServiceMode < 3) {
        SignalCallBack = new STCallBack() {

            @Override//from  w w  w . j  av  a2  s .  c om
            public void Call(Object argument) {
                SignalObject sig = (SignalObject) argument;
                Bundle data = new Bundle();
                data.putDouble("lat", sig.latitude);
                data.putDouble("lon", sig.longitude);
                data.putShort("signal", sig.signal);
                Message msg = new Message();
                msg.setData(data);
                msg.what = 0;
                if (!MainScreenHandler.sendMessage(msg)) {
                    Log.i("SignalTracker::MainScreen", "Failed to put signal on map. Delaying 2s");
                    MainScreenHandler.sendMessageDelayed(msg, 2000);
                }
            }

        };
        SignalCallBack.from = "MainScreen";

        CommonHandler.AddSignalCallback(SignalCallBack);
        if (CommonHandler.Signals != null) {
            for (int i = 0; i < CommonHandler.Signals.size(); i++)
                SignalCallBack.Call(CommonHandler.Signals.get(i));
        }
    }
    MainScreenHandler.postDelayed(UpdateUI, 100);
}

From source file:fr.mixit.android.ui.fragments.MembersListFragment.java

protected void refreshMembersData() {
    if (mIsBound && mServiceReady) {
        setRefreshMode(true);//ww  w.j a v a  2  s.  co m

        final Message msg = Message.obtain(null, MixItService.MSG_MEMBERS, 0, 0);
        msg.replyTo = mMessenger;
        final Bundle b = new Bundle();
        msg.setData(b);
        try {
            mService.send(msg);
        } catch (final RemoteException e) {
            e.printStackTrace();
        }

        mIsFirstLoad = false;
    } else {
        setRefreshMode(false);
    }
}

From source file:net.carlh.toast.Client.java

private void handler(JSONObject json) {
    try {/*from ww w  .  j  av  a  2 s . c o m*/
        if (json.has("type") && json.get("type").equals("pong")) {
            setConnected(true);
            pong.set(true);
        } else {
            for (Handler h : handlers) {
                Message m = Message.obtain();
                Bundle b = new Bundle();
                b.putString("json", json.toString());
                m.setData(b);
                h.sendMessage(m);
            }
        }
    } catch (JSONException e) {
    }
}