本文整理匯總了Java中android.os.Messenger.send方法的典型用法代碼示例。如果您正苦於以下問題:Java Messenger.send方法的具體用法?Java Messenger.send怎麽用?Java Messenger.send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.Messenger
的用法示例。
在下文中一共展示了Messenger.send方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendMessageToClient
import android.os.Messenger; //導入方法依賴的package包/類
/**
* Send the data to all clients.
* @param strToSend The String message to send.
*/
private static void sendMessageToClient(int typeOfMsg, String strToSend) {
Iterator<Messenger> messengerIterator = mClients.iterator();
while(messengerIterator.hasNext()) {
Messenger messenger = messengerIterator.next();
try {
switch (typeOfMsg) {
case MSG_SERVICE_TO_ROBOT:
messenger.send(messageComposer(messenger, MSG_SERVICE_TO_ROBOT, strToSend));
break;
case MSG_SERVICE_TO_GS:
messenger.send(messageComposer(messenger, MSG_SERVICE_TO_GS, strToSend));
break;
case MSG_ROBOT_TO_SERVICE:
messenger.send(messageComposer(messenger, MSG_ROBOT_TO_SERVICE, strToSend));
break;
}
} catch (RemoteException e) {
// The client is dead. Remove it from the list.
mClients.remove(messenger);
}
}
}
示例2: onServiceConnected
import android.os.Messenger; //導入方法依賴的package包/類
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
mServiceMessenger = new Messenger(iBinder);
//連接到服務
if (null != mServiceMessenger){
Message msgToService = Message.obtain();
msgToService.replyTo = mMessengerClient;
msgToService.what = Constant.LOCAL_MUSIC_ACTIVITY;
try {
mServiceMessenger.send(msgToService);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
示例3: sendGuestScienceCustomCommand
import android.os.Messenger; //導入方法依賴的package包/類
public void sendGuestScienceCustomCommand(String apk_name, String command) {
if (guest_science_apk_messengers_.containsKey(apk_name)) {
Messenger gs_apk_messenger = guest_science_apk_messengers_.get(apk_name);
Message msg = Message.obtain(null, MessageType.CMD.toInt());
Bundle data_bundle = new Bundle();
data_bundle.putString("command", command);
msg.setData(data_bundle);
try {
gs_apk_messenger.send(msg);
} catch (RemoteException e) {
e.printStackTrace();
}
} else {
Log.e("MessService.sendGSCmd", "Couldn't find messenger for " + apk_name +
". Thus cannot send command " + command + ".");
}
}
示例4: onServiceConnected
import android.os.Messenger; //導入方法依賴的package包/類
public void onServiceConnected(ComponentName className, IBinder service) {
// This is called when the connection with the service has been
// established, giving us the service object we can use to
// interact with the service. We are communicating with our
// service through an IDL interface, so get a client-side
// representation of that from the raw service object.
mBoundAutopilotService = new Messenger(service);
//mCallbackText.setText("Attached.");
// We want to monitor the service for as long as we are
// connected to it.
try {
Message msg = Message.obtain(null, autopilotService.MSG_REGISTER_CLIENT);
msg.replyTo = mMessenger;
mBoundAutopilotService.send(msg);
// Give it some value as an example.
msg = Message.obtain(null, autopilotService.MSG_SET_VALUE, this.hashCode(), 0);
mBoundAutopilotService.send(msg);
} catch (RemoteException e) {
// In this case the service has crashed before we could even
// do anything with it; we can count on soon being
// disconnected (and then reconnected if it can be restarted)
// so there is no need to do anything here.
}
}
示例5: sendGuestScienceStop
import android.os.Messenger; //導入方法依賴的package包/類
public boolean sendGuestScienceStop(String apkName) {
if (mApkMessengers.containsKey(apkName)) {
Messenger messenger = mApkMessengers.get(apkName);
Message msg = Message.obtain(null, MessageType.STOP.toInt());
try {
messenger.send(msg);
} catch (RemoteException e) {
ManagerNode.INSTANCE().getLogger().error(LOG_TAG, e.getMessage(), e);
return false;
}
} else {
ManagerNode.INSTANCE().getLogger().error(LOG_TAG, "Couldn't find messenger for " +
apkName + ". Thus cannot send a message to stop the apk.");
return false;
}
return true;
}
示例6: sendGuestScienceCustomCommand
import android.os.Messenger; //導入方法依賴的package包/類
public boolean sendGuestScienceCustomCommand(String apkName, String command) {
if (mApkMessengers.containsKey(apkName)) {
Messenger messenger = mApkMessengers.get(apkName);
Message msg = Message.obtain(null, MessageType.CMD.toInt());
Bundle data_bundle = new Bundle();
data_bundle.putString("command", command);
msg.setData(data_bundle);
try {
messenger.send(msg);
} catch (RemoteException e) {
ManagerNode.INSTANCE().getLogger().error(LOG_TAG, e.getMessage(), e);
return false;
}
} else {
ManagerNode.INSTANCE().getLogger().error(LOG_TAG, "Couldn't find messenger for " +
apkName + ". Thus cannot send command " + command + ".");
return false;
}
return true;
}
示例7: handleMessage
import android.os.Messenger; //導入方法依賴的package包/類
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MyConstants.MSG_FROM_CLIENT:
Log.i(TAG, "receive msg from Client:" + msg.getData().getString("msg"));
Messenger client = msg.replyTo;
Message relpyMessage = Message.obtain(null, MyConstants.MSG_FROM_SERVICE);
Bundle bundle = new Bundle();
bundle.putString("reply", "嗯,你的消息我已經收到,稍後會回複你。");
relpyMessage.setData(bundle);
try {
client.send(relpyMessage);
} catch (RemoteException e) {
e.printStackTrace();
}
break;
default:
super.handleMessage(msg);
}
}
示例8: handleMessage
import android.os.Messenger; //導入方法依賴的package包/類
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
try {
Messenger messenger = msg.replyTo;
Message replyMsg = Message.obtain(null, 4);
Bundle bundle = new Bundle();
bundle.putSerializable(StepCounterService.KEY_DATA_STEP,
StepCounterService.this.step);
bundle.putBoolean(StepCounterService.KEY_IS_ERROR, StepCounterService
.this.isError);
replyMsg.setData(bundle);
messenger.send(replyMsg);
return;
} catch (RemoteException e) {
e.printStackTrace();
return;
}
default:
super.handleMessage(msg);
return;
}
}
示例9: connectToSensorAndReply
import android.os.Messenger; //導入方法依賴的package包/類
private void connectToSensorAndReply(Intent intent) {
// Extract the Messenger from the Intent
Messenger messenger = (Messenger) intent.getExtras().get(SensorService.REPLY_MESSENGER);
// Get the replyCode to be returned back to the MagpieActivity
int replyCode = onStartConnection();
Message message = Message.obtain();
message.arg1 = replyCode;
try {
if (messenger != null) {
messenger.send(message);
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
示例10: onServiceConnected
import android.os.Messenger; //導入方法依賴的package包/類
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
mServiceMessenger = new Messenger(iBinder);
//連接到服務
if (null != mServiceMessenger) {
Message msgToService = Message.obtain();
msgToService.replyTo = mMessengerClient;
msgToService.what = Constant.COLLECTED_ACTIVITY;
try {
mServiceMessenger.send(msgToService);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
示例11: onServiceConnected
import android.os.Messenger; //導入方法依賴的package包/類
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
mServiceMessenger = new Messenger(iBinder);
//連接到服務
if (null != mServiceMessenger){
Message msgToService = Message.obtain();
msgToService.replyTo = mMessengerClient;
msgToService.what = Constant.JK_MUSIC_ACTIVITY;
try {
mServiceMessenger.send(msgToService);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
示例12: deliverMessage
import android.os.Messenger; //導入方法依賴的package包/類
public void deliverMessage(Messenger messager, int MsgType, Bundle data){
if (messager != null) {
Message msg = Message.obtain(null, MsgType, 0, 0);
try {
if (data != null) {
msg.setData(data);
}
messager.send(msg);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
示例13: onServiceConnected
import android.os.Messenger; //導入方法依賴的package包/類
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mService = new Messenger(service);
try {
Message message = Message.obtain(null, MsgService.MSG_REGISTER);
//回應的信使
message.replyTo = mMessenger;
mService.send(message);
} catch (RemoteException e) {
LogUtils.w(TAG, "連接服務錯誤");
mService = null;
e.printStackTrace();
}
mBound = true;
}
示例14: onServiceConnected
import android.os.Messenger; //導入方法依賴的package包/類
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mServiceMessenger = new Messenger(service);
mTextCommStatus.setText("Comm Status: Connected");
Log.i(LOGTAG, "CONNECTED to SERVICE!");
try {
Message msg = Message.obtain(null, MSG_REGISTER_CLIENT);
msg.replyTo = mMessenger;
mServiceMessenger.send(msg);
} catch (RemoteException re) {
// In this case the service has crashed before we could even do anything with it
}
mTextMsgGSToRobot.setText(gsApp.commandList.get(0).getString("cmd"));
gsApp.executeRobotInstructions("");
}
示例15: sendGuestScienceStop
import android.os.Messenger; //導入方法依賴的package包/類
public void sendGuestScienceStop(String apk_name) {
if (guest_science_apk_messengers_.containsKey(apk_name)) {
Messenger gs_apk_messenger = guest_science_apk_messengers_.get(apk_name);
Message msg = Message.obtain(null, MessageType.STOP.toInt());
try {
gs_apk_messenger.send(msg);
} catch (RemoteException e) {
e.printStackTrace();
}
} else {
Log.e("MessService.sendGSStop", "Couldn't find messenger for " + apk_name +
". Thus cannot send a message to stop the apk.");
}
}