List of usage examples for android.os Messenger send
public void send(Message message) throws RemoteException
From source file:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java
@Override public void onVoiceRecognitionStarted() { // // ww w .j av a 2 s .c om for (Messenger x : mCallbackMessengers) { try { x.send(Message.obtain(null, 5, 0, 0)); } catch (RemoteException e) { Log.e(TAG, "Callback error!"); } } }
From source file:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java
@Override public void onVoiceRecognitionStopped() { // /*ww w . ja v a2 s . c om*/ for (Messenger x : mCallbackMessengers) { try { x.send(Message.obtain(null, 6, 0, 0)); } catch (RemoteException e) { Log.e(TAG, "Callback error!"); } } }
From source file:com.marianhello.bgloc.LocationService.java
public void sendClientMessage(Message msg) { Iterator<Messenger> it = mClients.values().iterator(); while (it.hasNext()) { try {/*from ww w .ja v a 2 s. c om*/ Messenger client = it.next(); client.send(msg); } 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. it.remove(); } } }
From source file:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java
/** * @see BluetoothHeadsetMonitor.BluetoothHeadsetMonitorDelegate#onBluetoothStarted() * *//* www.ja v a2 s. com*/ @Override public void onBluetoothStarted() { if (mCallbackMessengers.isEmpty()) { // final NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.headset_launcher_notification) .setContentTitle(getString(R.string.text_bluetooth_started)).setAutoCancel(true); final NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(1, builder.build()); // ? ? ? mTimer.start(); } else { // for (Messenger x : mCallbackMessengers) { try { x.send(Message.obtain(null, 1, 0, 0)); } catch (RemoteException e) { Log.e(TAG, "Callback error!"); } } } }
From source file:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java
/** * @see BluetoothHeadsetMonitor.BluetoothHeadsetMonitorDelegate#onBluetoothStopped() * */// w w w . ja v a2 s . c om @Override public void onBluetoothStopped() { if (mCallbackMessengers.isEmpty()) { // final NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.headset_launcher_notification) .setContentTitle(getString(R.string.text_bluetooth_stopped)).setAutoCancel(true); final NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(1, builder.build()); // ? ? ? mTimer.start(); } else { // for (Messenger x : mCallbackMessengers) { try { x.send(Message.obtain(null, 2, 0, 0)); } catch (RemoteException e) { Log.e(TAG, "Callback error!"); } } } }
From source file:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java
/** * @see BluetoothHeadsetMonitor.BluetoothHeadsetMonitorDelegate#onHeadsetDisconnected() * *///from w ww . java 2 s. c o m @Override public void onHeadsetDisconnected() { if (mCallbackMessengers.isEmpty()) { // final NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.headset_launcher_notification) .setContentTitle(getString(R.string.text_headset_disconnected)).setAutoCancel(true); final NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(1, builder.build()); // ? ? ? mTimer.start(); } else { // for (Messenger x : mCallbackMessengers) { try { x.send(Message.obtain(null, 4, 0, 0)); } catch (RemoteException e) { Log.e(TAG, "Callback error!"); } } } }
From source file:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java
/** * @see BluetoothHeadsetMonitor.BluetoothHeadsetMonitorDelegate#onHeadsetConnected(String) * *//*from www.ja va 2s .c o m*/ @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:org.sufficientlysecure.keychain.service.PassphraseCacheService.java
/** * Executed when service is started by intent *//*from w w w . j a va 2s . c o m*/ @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "onStartCommand()"); // register broadcastreceiver registerReceiver(); if (intent != null && intent.getAction() != null) { if (ACTION_PASSPHRASE_CACHE_ADD.equals(intent.getAction())) { long ttl = intent.getLongExtra(EXTRA_TTL, DEFAULT_TTL); long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1); String passphrase = intent.getStringExtra(EXTRA_PASSPHRASE); Log.d(TAG, "Received ACTION_PASSPHRASE_CACHE_ADD intent in onStartCommand() with keyId: " + keyId + ", ttl: " + ttl); // add keyId and passphrase to memory mPassphraseCache.put(keyId, passphrase); if (ttl > 0) { // register new alarm with keyId for this passphrase long triggerTime = new Date().getTime() + (ttl * 1000); AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, triggerTime, buildIntent(this, keyId)); } } else if (ACTION_PASSPHRASE_CACHE_GET.equals(intent.getAction())) { long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1); Messenger messenger = intent.getParcelableExtra(EXTRA_MESSENGER); String passphrase = getCachedPassphraseImpl(keyId); Message msg = Message.obtain(); Bundle bundle = new Bundle(); bundle.putString(EXTRA_PASSPHRASE, passphrase); msg.obj = bundle; try { messenger.send(msg); } catch (RemoteException e) { Log.e(Constants.TAG, "Sending message failed", e); } } else { Log.e(Constants.TAG, "Intent or Intent Action not supported!"); } } return START_STICKY; }
From source file:com.ratebeer.android.gui.components.PosterService.java
private void callbackMessenger(Intent intent, int result) { if (intent.hasExtra(EXTRA_MESSENGER)) { // Prepare a message Messenger callback = intent.getParcelableExtra(EXTRA_MESSENGER); Message msg = Message.obtain();//from w ww. j a v a 2 s . c o m msg.arg1 = result; try { // Send it back to the messenger, i.e. the activity callback.send(msg); } catch (RemoteException e) { Log.e(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Cannot call back to activity to deliver message '" + msg.toString() + "'"); } } }
From source file:org.sufficientlysecure.keychain.ui.dialog.OrbotStartDialogFragment.java
@NonNull @Override// www.j av a2 s . c o m public Dialog onCreateDialog(Bundle savedInstanceState) { final Messenger messenger = getArguments().getParcelable(ARG_MESSENGER); int title = getArguments().getInt(ARG_TITLE); final int message = getArguments().getInt(ARG_MESSAGE); int middleButton = getArguments().getInt(ARG_MIDDLE_BUTTON); final Activity activity = getActivity(); ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity); CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(theme); builder.setTitle(title).setMessage(message); builder.setNegativeButton(R.string.orbot_start_dialog_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Message msg = Message.obtain(); msg.what = MESSAGE_DIALOG_CANCELLED; try { messenger.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); } } }); builder.setNeutralButton(middleButton, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Message msg = new Message(); msg.what = MESSAGE_MIDDLE_BUTTON; try { messenger.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); } } }); builder.setPositiveButton(R.string.orbot_start_dialog_start, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // actual onClick defined in onStart, this is just to make the button appear } }); return builder.show(); }