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:org.smilec.smile.student.CourseList.java

public void setTranferStatus(boolean is_send, int time) { // called by junction object
    // 0: finished
    // 1~20: how many time has passed
    if (is_send)// w  w  w . j a v  a  2  s  . c  om
        messageHandler.sendMessage(Message.obtain(messageHandler, HTTP_SEND_STATUS, time, 0));
    else
        messageHandler.sendMessage(Message.obtain(messageHandler, HTTP_PING_STATUS, time, 0));
    // below Handler will be called soon enough with 'todo_number' as
    // msg.what
}

From source file:com.example.helloworldlinked.backend.HelloWorldService.java

public void sendMessage(String textMessage) {
    JSONObject jObj = createTextJSONObject(textMessage);
    Bundle providerData = new Bundle(1);
    providerData.putString(BUNDLE_DATA, jObj.toString());
    Message providerMsg = Message.obtain(null, MSG_TO_HELLOWORLDPROVIDERSERVICE, 0, 0);
    providerMsg.setData(providerData);/* w  w  w.j  a v a 2  s  . c  o m*/

    sendToProviderService(providerMsg);
}

From source file:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java

/**
 * @see BluetoothHeadsetMonitor.BluetoothHeadsetMonitorDelegate#onHeadsetDisconnected()
 *
 *//* w  ww .j a v a2  s .  com*/
@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:com.example.helloworldlinked.backend.HelloWorldService.java

public void sendResetCountMessage() {
    JSONObject jObj = createResetJSONObject();
    Bundle providerData = new Bundle(1);
    providerData.putString(BUNDLE_DATA, jObj.toString());
    Message providerMsg = Message.obtain(null, MSG_TO_HELLOWORLDPROVIDERSERVICE, 0, 0);
    providerMsg.setData(providerData);/*from   w  w w. j av a 2  s .c  o m*/

    sendToProviderService(providerMsg);
}

From source file:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java

@Override
public void onVoiceRecognitionStarted() {

    //  /*from  w  w w. j av a2 s .c  o m*/

    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() {

    //  /*from ww  w  .j  av  a  2  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.google.android.DemoKit.DemoKitActivity.java

@Override
public void onPause() {
    super.onPause();
    if (mAccessoryController == null) {
        //         Toast.makeText(this, "onPause of DemoKitActivity - Accessory Controller is null", Toast.LENGTH_SHORT).show();
        return;// w w  w .java  2 s. c  om
    } else {

        try {
            mAccessoryController.send(Message.obtain(null, UsbMessages.STOP_CONTROLLER, 0, 0));
        } catch (RemoteException e) {
        }
        ;
    }

}

From source file:org.openbmap.services.MasterBrainService.java

/**
 * Updates database and stops sub-services after stop request
 * @param reason//from  w w w  . ja v a  2s  .  c om
 */
private void stopTracking(int reason) {
    unbindAll();

    updateDatabase();

    for (int i = mClients.size() - 1; i >= 0; i--) {
        try {
            mClients.get(i).send(Message.obtain(null, RadioBeacon.MSG_SERVICE_SHUTDOWN, reason, 0));
        } 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);
        }
    }

    hideNotification();
}

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

protected void getStarredSessions(int memberId) {
    if (mIsBound && mServiceReady) {
        final Message msg = Message.obtain(null, MixItService.MSG_GET_STARRED_SESSION, 0, 0);
        msg.replyTo = mMessenger;//  w  ww  .ja  v  a 2s. c  o  m
        final Bundle b = new Bundle();
        b.putInt(MixItService.EXTRA_MEMBER_ID, memberId);
        msg.setData(b);
        try {
            mService.send(msg);
            setRefreshMode(true);
        } catch (final RemoteException e) {
            e.printStackTrace();
        }
    }
}

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

public void onClickSendHexFile(View v) {
    Toast.makeText(this, "Click received from Send Hex File", Toast.LENGTH_SHORT).show();
    try {/*  w  w w .  j  av a 2 s  .c  o m*/
        mAccessoryController.send(Message.obtain(null, UsbMessages.SEND_HEX, 0, 0));
    } catch (RemoteException e) {
    }
    ;
}