List of usage examples for android.os Message setData
public void setData(Bundle data)
From source file:com.yangtsaosoftware.pebblemessenger.services.NotificationService.java
@Override public void onNotificationPosted(StatusBarNotification sbn) { if (sbn == null) return;/*w ww . j a v a2s .c o m*/ Constants.log(LOG_TAG, "New Access Event:" + sbn.getPackageName() + " tag:" + sbn.getTag()); /*if(event.getEventType()!= AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED){ return; } */ PowerManager powMan = (PowerManager) this.getSystemService(POWER_SERVICE); if (!notifScreenOn && powMan.isScreenOn()) { Constants.log(LOG_TAG, "because screen out!"); return; } //Parcelable parcelable=event.getParcelableData(); //if(!(parcelable instanceof Notification)) return; Notification notif = sbn.getNotification(); if (sbn.isOngoing()) { Constants.log(LOG_TAG, "because is Ongoing!"); return; } String eventPackageName; if (sbn.getPackageName() != null) { eventPackageName = sbn.getPackageName(); } else { Constants.log(LOG_TAG, "Can't get event package name. Returning."); return; } boolean found = false; for (String packageName : packages) { if (packageName.equalsIgnoreCase(eventPackageName)) { found = true; break; } } if (!found) { Constants.log(LOG_TAG, eventPackageName + " was not found in the include list. Returning."); return; } String title = eventPackageName.substring(eventPackageName.lastIndexOf('.') + 1); // get the notification text Bundle notiBundle = notif.extras; StringBuilder notifySb = new StringBuilder(); CharSequence notifyChars = notiBundle.getCharSequence(Notification.EXTRA_TITLE); if (notifyChars != null) { notifySb.append(notifyChars); } else { Constants.log(LOG_TAG, "empty message title,return!"); return; } CharSequence bodyCS = notiBundle.getCharSequence(Notification.EXTRA_TEXT); if (bodyCS != null) { notifySb.append(":"); notifySb.append(bodyCS); } else { Constants.log(LOG_TAG, "empty message body,return!" + notifySb.toString()); return; } bodyCS = notiBundle.getCharSequence(Notification.EXTRA_SUB_TEXT); if (bodyCS != null) { notifySb.append(bodyCS); } Message msg = Message.obtain(); msg.what = MessageProcessingService.MSG_NEW_MESSAGE; Bundle b = new Bundle(); b.putString(MessageDbHandler.COL_MESSAGE_APP, title); b.putString(MessageDbHandler.COL_MESSAGE_CONTENT, notifySb.toString()); Constants.log(LOG_TAG, "Send new message title:" + title + " body:" + notifySb.toString()); msg.setData(b); try { rMessageProcessHandler.send(msg); } catch (RemoteException e) { e.printStackTrace(); Constants.log(LOG_TAG, "Error when sending message to MessageProcessingService."); } }
From source file:uk.ac.gcu.bluedroid.BluetoothChatService.java
/** * Indicate that the connection attempt failed and notify the UI Activity. *//*from ww w . j av a 2 s . c o m*/ private void connectionFailed() { // Send a failure message back to the Activity Message msg = mHandler.obtainMessage(MainActivity.MESSAGE_TOAST); Bundle bundle = new Bundle(); bundle.putString(MainActivity.TOAST, "Unable to connect device"); msg.setData(bundle); mHandler.sendMessage(msg); // Start the service over to restart listening mode BluetoothChatService.this.start(); }
From source file:uk.ac.gcu.bluedroid.BluetoothChatService.java
/** * Indicate that the connection was lost and notify the UI Activity. *//*from www .ja va2 s .com*/ private void connectionLost() { // Send a failure message back to the Activity Message msg = mHandler.obtainMessage(MainActivity.MESSAGE_TOAST); Bundle bundle = new Bundle(); bundle.putString(MainActivity.TOAST, "Device connection was lost"); msg.setData(bundle); mHandler.sendMessage(msg); // Start the service over to restart listening mode BluetoothChatService.this.start(); }
From source file:com.google.android.DemoKit.DemoKitActivity.java
/** Called when the activity is first created. */ @Override/*from w w w .ja va 2 s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = getApplicationContext(); // Toast.makeText(this, "inside onCreate of DemoKitActivity", Toast.LENGTH_SHORT).show(); IntentFilter connFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); mConnReceiver = new ConnBroadcastReceiver(); registerReceiver(mConnReceiver, connFilter); setContentView(R.layout.main); enableControls(true); mNocServiceRequestor = new PeriodicScheduler(new Runnable() { @Override public void run() { if (mNocAccessServiceMessenger != null) { toastHandler("Trying to upload Sensor Data"); // if(mConnReceiver.isConnected) { Message msg = Message.obtain(null, NocMessages.URL_MSG, 0, 0); Bundle msgBundle = new Bundle(); msgBundle.putString("url", "http://98.26.23.101/update.php?req=UI:WLDCTLAB1;FV:1.36;E1:0;EC1:0;E2:0;EC2:0;FL:2937;FC:0;BA:1218;TO:2181;TC:2181;FL20:0;FE:0;BL:0;HTO:0;HTC:0;BP1:0;BP2:0;GF:0;UF:1;IN:0;DT:0;TCF:0;TOF:0"); msg.setData(msgBundle); try { mNocAccessServiceMessenger.send(msg); } catch (RemoteException e) { } } else { toastHandler("mNocAccessServiceMessenger is null!"); } } }, 5000); mBTMsgHandler = new Messenger(new BluetoothMsgHandler()); mAccessoryMsgHandler = new Messenger(new ServiceMsgHandler()); mNocMsgHandler = new Messenger(new ServiceMsgHandler()); }
From source file:uk.ac.gcu.bluedroid.BluetoothChatService.java
/** * Start the ConnectedThread to begin managing a Bluetooth connection * /* w ww .ja v a 2 s . com*/ * @param socket * The BluetoothSocket on which the connection was made * @param device * The BluetoothDevice that has been connected */ public synchronized void connected(BluetoothSocket socket, BluetoothDevice device, final String socketType) { if (D) Log.d(TAG, "connected, Socket Type:" + 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(MainActivity.MESSAGE_DEVICE_NAME); Bundle bundle = new Bundle(); bundle.putString(MainActivity.DEVICE_NAME, device.getName()); msg.setData(bundle); mHandler.sendMessage(msg); setState(STATE_CONNECTED); }
From source file:com.dzt.uberclone.HomeFragment.java
private void trackDriver() { trackDriverBoolean = true;/*from w ww . j ava 2 s. co m*/ Thread trackdriverthread = new Thread(new Runnable() { @Override public void run() { while (true) { if (trackDriverBoolean) { String response = trackDriverPosition(); threadMsg(response); } else { return; } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } private void threadMsg(String msg) { if (!msg.equals(null) && !msg.equals("")) { Message msgObj = handler.obtainMessage(); Bundle b = new Bundle(); b.putString("message", msg); msgObj.setData(b); handler.sendMessage(msgObj); } } private final Handler handler = new Handler() { public void handleMessage(Message msg) { String aResponse = msg.getData().getString("message"); Log.i("aresponse", aResponse); if ((null != aResponse)) { handleDriverTracking(aResponse); } else { Toast.makeText(getActivity(), "Not Got Response From Server.", Toast.LENGTH_SHORT).show(); } } }; }); trackdriverthread.start(); }
From source file:com.dzt.uberclone.HomeFragment.java
public void waitForUberDriver(final int pendingrideid) { Thread timer = new Thread(new Runnable() { @Override//from ww w .j a v a2 s.c o m public void run() { while (true) { if (syncWithServer) { String response = syncForUber(pendingrideid); threadMsg(response); } else { return; } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } private void threadMsg(String msg) { if (!msg.equals(null) && !msg.equals("")) { Message msgObj = handler.obtainMessage(); Bundle b = new Bundle(); b.putString("message", msg); msgObj.setData(b); handler.sendMessage(msgObj); } } private final Handler handler = new Handler() { public void handleMessage(Message msg) { String aResponse = msg.getData().getString("message"); Log.i("aresponse", aResponse); if ((null != aResponse)) { if (aResponse.equals("Waiting")) { statusText.setVisibility(View.VISIBLE); statusText.setText("Waiting for a driver to accept"); } else { showDriverData(aResponse); syncWithServer = false; } } else { Toast.makeText(getActivity(), "Not Got Response From Server.", Toast.LENGTH_SHORT).show(); } } }; }); timer.start(); }
From source file:fr.mixit.android.ui.fragments.SessionsListFragment.java
protected void refreshSessionsData() { if (mIsBound && mServiceReady) { Message msg = null; if (mMode == SessionsActivity.DISPLAY_MODE_SESSIONS) { msg = Message.obtain(null, MixItService.MSG_TALKS, 0, 0); } else if (mMode == SessionsActivity.DISPLAY_MODE_LIGHTNING_TALKS) { msg = Message.obtain(null, MixItService.MSG_LIGHTNING_TALKS, 0, 0); }/*from w w w . java 2s . com*/ if (msg != null) { setRefreshMode(true); 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:com.authorwjf.bounce.BluetoothChatService.java
/** * Indicate that the connection attempt failed and notify the UI Activity. *//* w w w . j a va 2s . c o m*/ private void connectionFailed() { // Send a failure message back to the Activity Message msg = mHandler.obtainMessage(BluetoothChat.MESSAGE_TOAST); Bundle bundle = new Bundle(); bundle.putString(BluetoothChat.TOAST, "Unable to connect device"); msg.setData(bundle); mHandler.sendMessage(msg); // Start the service over to restart listening mode BluetoothChatService.this.start(); }
From source file:com.authorwjf.bounce.BluetoothChatService.java
/** * Indicate that the connection was lost and notify the UI Activity. *///from w w w . j av a 2 s . co m private void connectionLost() { // Send a failure message back to the Activity Message msg = mHandler.obtainMessage(BluetoothChat.MESSAGE_TOAST); Bundle bundle = new Bundle(); bundle.putString(BluetoothChat.TOAST, "Device connection was lost"); msg.setData(bundle); mHandler.sendMessage(msg); // Start the service over to restart listening mode BluetoothChatService.this.start(); }