List of usage examples for android.os Message setData
public void setData(Bundle data)
From source file:com.authorwjf.bounce.BluetoothChatService.java
/** * Start the ConnectedThread to begin managing a Bluetooth connection * @param socket The BluetoothSocket on which the connection was made * @param device The BluetoothDevice that has been connected *//*from ww w . j a v a2 s .c o m*/ public synchronized void connected(BluetoothSocket socket, BluetoothDevice device, final String socketType) { // Cancel the thread that completed the connection if (mConnectThread != null) { mConnectThread.cancel(); mConnectThread = null; } // Cancel any thread currently running a connection if (mConnectedThread != null) { mConnectedThread.cancel(); mConnectedThread = null; } // Cancel the accept thread because we only want to connect to one device if (mSecureAcceptThread != null) { mSecureAcceptThread.cancel(); mSecureAcceptThread = null; } if (mInsecureAcceptThread != null) { mInsecureAcceptThread.cancel(); mInsecureAcceptThread = null; } // Start the thread to manage the connection and perform transmissions mConnectedThread = new ConnectedThread(socket, socketType); mConnectedThread.start(); // Send the name of the connected device back to the UI Activity Message msg = mHandler.obtainMessage(BluetoothChat.MESSAGE_DEVICE_NAME); Bundle bundle = new Bundle(); bundle.putString(BluetoothChat.DEVICE_NAME, device.getName()); msg.setData(bundle); mHandler.sendMessage(msg); setState(STATE_CONNECTED); }
From source file:com.firescar96.nom.GCMIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();/*from w w w.ja v a 2 s. c om*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) Log.i(Consts.TAG, "onHandleIntent: message error"); else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) Log.i(Consts.TAG, "onHandleIntent: message deleted"); // If it's a regular GCM message, do some work. else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Post notification of received message. System.out.println("Received: " + extras.toString()); if (context == null) { System.out.println("null conxtext"); /*Intent needIntent = new Intent(this, MainActivity.class); needIntent.putExtra("purpose", "update"); needIntent.putExtra("mate", (String)extras.get("mate")); needIntent.putExtra("event", (String)extras.get("event")); needIntent.putExtra("chat", (String)extras.get("chat")); needIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(needIntent);*/ System.out.println(getFilesDir().getAbsolutePath()); MainActivity.initAppData(getFilesDir().getAbsolutePath()); } try { if (extras.get("mate") != null) { //context.appData.getJSONArray("mates").put(extras.get("mate")); } if (extras.get("event") != null) { JSONObject eveData = new JSONObject("{\"event\":" + extras.get("event") + "}") .getJSONObject("event"); JSONArray eve = MainActivity.appData.getJSONArray("events"); for (int i = 0; i < eve.length(); i++) { System.out.println(eveData.getString("hash")); System.out.println(eve.getJSONObject(i).getString("hash")); if (eveData.getString("hash").equals(eve.getJSONObject(i).getString("hash"))) return; } eveData.accumulate("member", false); System.out.println(eveData.getLong("date")); System.out.println(Calendar.getInstance().getTimeInMillis()); if (eveData.getLong("date") < Calendar.getInstance().getTimeInMillis()) return; eve.put(eveData); Message msg = new Message(); Bundle data = new Bundle(); data.putString("type", "event." + eveData.getString("privacy")); data.putString("host", eveData.getString("host")); data.putString("date", eveData.getString("date")); msg.setData(data); contextHandler.sendMessage(msg); } if (extras.get("chat") != null) { JSONObject chatData = new JSONObject("{\"chat\":" + extras.get("chat") + "}") .getJSONObject("chat"); JSONArray eve = MainActivity.appData.getJSONArray("events"); for (int i = 0; i < eve.length(); i++) if (chatData.getString("hash").equals(eve.getJSONObject(i).getString("hash"))) { JSONObject msgSon = new JSONObject(); msgSon.accumulate("author", chatData.getString("author")); msgSon.accumulate("message", chatData.getString("message")); eve.getJSONObject(i).getJSONArray("chat").put(msgSon); Message msg = new Message(); Bundle data = new Bundle(); data.putString("type", "chat"); data.putString("author", chatData.getString("author")); data.putString("message", chatData.getString("message")); data.putBoolean("member", eve.getJSONObject(i).getBoolean("member")); data.putString("hash", chatData.getString("hash")); msg.setData(data); contextHandler.sendMessage(msg); return; } } MainActivity.closeAppData(getFilesDir().getAbsolutePath()); } catch (JSONException e1) { e1.printStackTrace(); } } // Release the wake lock provided by the WakefulBroadcastReceiver. MainBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.lib.DstabiProvider.java
private void sendHandleNotStop(int callBackCode, byte[] data) { Bundle budleForMsg = new Bundle(); budleForMsg.putByteArray("data", data); Message m = connectionHandler.obtainMessage(callBackCode); m.setData(budleForMsg); connectionHandler.sendMessage(m);//from w w w . j a v a2 s . c om //Log.d(TAG, "zprava poslana not stop: " + callBackCode); }
From source file:com.lib.DstabiProvider.java
private void sendHandle(int callBackCode, byte[] data) { Bundle budleForMsg = new Bundle(); budleForMsg.putByteArray("data", data); Message m = connectionHandler.obtainMessage(callBackCode); m.setData(budleForMsg); connectionHandler.sendMessage(m);/*from w w w . j a v a 2s.co m*/ Log.d(TAG, "zprava poslana"); clearState("send handle"); }
From source file:org.harleydroid.HarleyDroidService.java
public void setSendData(String type[], String ta[], String sa[], String command[], String expect[], int timeout[], int delay) { if (D)//from w w w. j a v a 2 s . co m Log.d(TAG, "setSendData()"); Message m = mServiceHandler.obtainMessage(MSG_SET_SEND); Bundle b = new Bundle(); b.putStringArray("type", type); b.putStringArray("ta", ta); b.putStringArray("sa", sa); b.putStringArray("command", command); b.putStringArray("expect", expect); b.putIntArray("timeout", timeout); b.putInt("delay", delay); m.setData(b); //mServiceHandler.removeCallbacksAndMessages(null); m.sendToTarget(); }
From source file:org.harleydroid.HarleyDroidService.java
public void startSend(String type[], String ta[], String sa[], String command[], String expect[], int timeout[], int delay) { if (D)//from w ww . j av a 2 s . c o m Log.d(TAG, "send()"); Message m = mServiceHandler.obtainMessage(MSG_START_SEND); Bundle b = new Bundle(); b.putStringArray("type", type); b.putStringArray("ta", ta); b.putStringArray("sa", sa); b.putStringArray("command", command); b.putStringArray("expect", expect); b.putIntArray("timeout", timeout); b.putInt("delay", delay); m.setData(b); //mServiceHandler.removeCallbacksAndMessages(null); m.sendToTarget(); }
From source file:com.xmobileapp.rockplayer.LastFmEventImporter.java
/********************************* * // w w w.j a va 2s. c o m * Constructor * @param context * *********************************/ public LastFmEventImporter(Context context) { this.context = context; Log.i("LASTFMEVENT", "creating-------------------------"); /* * Check for Internet Connection (Through whichever interface) */ ConnectivityManager connManager = (ConnectivityManager) ((RockPlayer) context) .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connManager.getActiveNetworkInfo(); /******* EMULATOR HACK - false condition needs to be removed *****/ //if (false && (netInfo == null || !netInfo.isConnected())){ if ((netInfo == null || !netInfo.isConnected())) { Bundle data = new Bundle(); data.putString("info", "No Internet Connection"); Message msg = new Message(); msg.setData(data); ((RockPlayer) context).analyseConcertInfoHandler.sendMessage(msg); return; } /* * Get location */ MIN_UPDATE_INTVL = 5 * 24 * 60 * 60 * 1000; // 5 days SPREAD_INTVL = 21 * 24 * 60 * 60 * 1000; // 21 days; Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); LocationManager locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (locManager.getBestProvider(criteria, true) != null) myLocation = locManager.getLastKnownLocation(locManager.getBestProvider(criteria, true)); else { myLocation = new Location("gps"); myLocation.setLatitude(47.100301); myLocation.setLongitude(-119.982465); } /* * Get preferred distance */ // SharedPreferences prefs = ((Filex) context).getSharedPreferences(((Filex) context).PREFS_NAME, 0); RockOnPreferenceManager prefs = new RockOnPreferenceManager(((RockPlayer) context).FILEX_PREFERENCES_PATH); concertRadius = prefs.getLong("ConcertRadius", (long) (((RockPlayer) context).CONCERT_RADIUS_DEFAULT)); //myLocation = locManager.getLastKnownLocation(locManager.getBestProvider(Criteria.POWER_LOW, true)); // try { // getArtistEvents(); // } catch (SAXException e) { // e.printStackTrace(); // } catch (ParserConfigurationException e) { // e.printStackTrace(); // } }
From source file:net.evecom.androidecssp.base.BaseActivity.java
/** * /* w ww . j ava 2 s . co m*/ * dictValue dictKey TextViewDictName * * @author Mars zhang * @created 2015-11-25 9:50:55 * @param dictKey * @param value * @param view */ protected void setDictNameByValueToView(final String dictKey, final String dictValue, final TextView view) { final Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case MESSAGETYPE_01: view.setText(msg.getData().getString("dictname")); break; default: break; } }; }; new Thread(new Runnable() { @Override public void run() { try { HashMap<String, String> entityMap = new HashMap<String, String>(); entityMap.put("dictkey", dictKey); String result = connServerForResultPost("jfs/ecssp/mobile/pubCtr/getDictByKey", entityMap); List<BaseModel> baseModels = getObjsInfo(result); HashMap<String, String> keyValehashmap = new HashMap<String, String>(); for (int i = 0; i < baseModels.size(); i++) { keyValehashmap.put(baseModels.get(i).get("dictvalue") + "", baseModels.get(i).get("name") + ""); } String dictname = ifnull(keyValehashmap.get(dictValue), ""); Message message = new Message(); Bundle mbundle = new Bundle(); mbundle.putString("dictname", dictname); message.setData(mbundle); message.what = MESSAGETYPE_01; mHandler.sendMessage(message); } catch (ClientProtocolException e) { Log.v("mars", e.getMessage()); } catch (IOException e) { Log.v("mars", e.getMessage()); } catch (JSONException e) { Log.v("mars", e.getMessage()); } } }).start(); }
From source file:net.evecom.androidecssp.base.BaseActivity.java
/** * /*from w w w . j a v a2 s. c o m*/ * dictValue dictKey TextViewDictName * * @author Mars zhang * @created 2015-11-25 9:50:55 * @param dictKey * @param value * @param view */ protected void setLikeDictNameByValueToView(final String url, final String dictKey, final String dictValue, final TextView view) { final Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case MESSAGETYPE_01: view.setText(msg.getData().getString("dictname")); break; default: break; } }; }; new Thread(new Runnable() { @Override public void run() { try { HashMap<String, String> entityMap = new HashMap<String, String>(); entityMap.put("dictkey", dictKey); String result = connServerForResultPost(url, entityMap); List<BaseModel> baseModels = getObjsInfo(result); HashMap<String, String> keyValehashmap = new HashMap<String, String>(); for (int i = 0; i < baseModels.size(); i++) { keyValehashmap.put(baseModels.get(i).get("dictvalue") + "", baseModels.get(i).get("name") + ""); } String dictname = ifnull(keyValehashmap.get(dictValue), ""); Message message = new Message(); Bundle mbundle = new Bundle(); mbundle.putString("dictname", dictname); message.setData(mbundle); message.what = MESSAGETYPE_01; mHandler.sendMessage(message); } catch (ClientProtocolException e) { Log.v("mars", e.getMessage()); } catch (IOException e) { Log.v("mars", e.getMessage()); } catch (JSONException e) { Log.v("mars", e.getMessage()); } } }).start(); }
From source file:com.cttapp.bby.mytlc.layer8apps.CalendarHandler.java
/************ * PURPOSE: Used to send our updates back to the main thread * ARGUMENTS: String status/* ww w . j av a2 s .c o m*/ * RETURNS: VOID * AUTHOR: Devin Collins <agent14709@gmail.com> *************/ private void updateStatus(String status) { Message msg = Message.obtain(); Bundle data = new Bundle(); data.putString("status", status); msg.setData(data); try { messenger.send(msg); } catch (Exception e) { // TODO: Error reporting? } }