Example usage for android.os Message obtain

List of usage examples for android.os Message obtain

Introduction

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

Prototype

public static Message obtain(Handler h, int what, int arg1, int arg2) 

Source Link

Document

Same as #obtain() , but sets the values of the target, what, arg1, and arg2 members.

Usage

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;//from  www .  j a  v a  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:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java

/**
 * @see BluetoothHeadsetMonitor.BluetoothHeadsetMonitorDelegate#onBluetoothStopped()
 *
 *//*  w ww . java2 s  .co  m*/
@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:com.google.android.DemoKit.DemoKitActivity.java

@Override
public void onResume() {
    super.onResume();

    mNocServiceRequestor.startUpdates();

    if (mAccessoryController == null) {
        //         Toast.makeText(this, "onResume of DemoKitActivity - Accessory Controller is null", Toast.LENGTH_SHORT).show();
    } else {//  www  . ja v  a 2  s . co m
        try {
            mAccessoryController.send(Message.obtain(null, UsbMessages.START_CONTROLLER, 0, 0));
        } catch (RemoteException e) {
        }
        ;
    }

    /*      SmsManager smsMgr = SmsManager.getDefault();
                  
          try {
             Toast.makeText(context, "Trying to send SMS...", Toast.LENGTH_SHORT).show();
             smsMgr.sendTextMessage("9197445298", null, "Test message from Galaxy S4", null, null);
          } catch (IllegalArgumentException e) {
             Toast.makeText(context, "Got Exception when trying to send SMS", Toast.LENGTH_SHORT).show();
          }
    */
}

From source file:com.first3.viz.download.DownloadManager.java

private void sendProgressUpdate(Resource resource, int progress) {
    Message m = Message.obtain(null, MSG_STATUS_DOWNLOAD_PROGRESS, progress, 0);
    Bundle bundle = new Bundle();
    bundle.putParcelable(DownloadManager.RESOURCE, resource);
    m.setData(bundle);/*from w  ww.  j av  a  2s  .c om*/
    sendMsg(m);
}

From source file:es.curso.android.streamingVLC.VideoActivity.java

@Override
public void setSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num,
        int sar_den) {
    Message msg = Message.obtain(mHandler, VideoSizeChanged, width, height);
    msg.sendToTarget();// w  ww . j  a  va  2 s.co m
}

From source file:com.google.android.DemoKit.DemoKitActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    String action = intent.getAction();
    if (action.equals(UsbManager.ACTION_USB_ACCESSORY_ATTACHED)) {
        try {/*from  w  w  w .  j a  va 2 s.c om*/
            mAccessoryController.send(Message.obtain(null, UsbMessages.ACCESSORY_ATTACHED, 0, 0));
        } catch (RemoteException e) {
        }
        ;
    }

}

From source file:com.vuze.android.remote.service.VuzeService.java

public void sendStuff(int what, String s) {
    for (int i = mClients.size() - 1; i >= 0; i--) {
        try {/*from  w w  w .ja v  a 2 s  . c o m*/
            Message obtain = Message.obtain(null, what, 0, 0);
            if (s != null) {
                Bundle bundle = new Bundle();
                bundle.putString("data", s);
                obtain.setData(bundle);
            }
            mClients.get(i).send(obtain);
        } 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:fr.mixit.android.ui.fragments.SessionsListFragment.java

protected void refreshSessionsData() {
    if (mIsBound && mServiceReady) {
        Message msg = null;/* w w w .j  av  a  2 s .  com*/
        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);
        }
        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:fr.mixit.android.ui.fragments.MembersListFragment.java

protected void refreshMembersData() {
    if (mIsBound && mServiceReady) {
        setRefreshMode(true);//w  w  w  .  java 2  s  .  c  om

        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:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java

/**
 * @see BluetoothHeadsetMonitor.BluetoothHeadsetMonitorDelegate#onHeadsetConnected(String)
 *
 *///from w  ww.  j  a v  a2  s  . 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!");
            }
        }
    }
}