Java 类android.os.Messenger 实例源码
项目:q-mail
文件:SMimeApi.java
public <T> CancelableBackgroundOperation executeApiAsync(Intent data, SMimeDataSource dataSource,
SMimeDataSink<T> dataSink, final ISMimeSinkResultCallback<T> callback) {
Messenger messenger = new Messenger(new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
callback.onProgress(message.arg1, message.arg2);
return true;
}
}));
data.putExtra(EXTRA_PROGRESS_MESSENGER, messenger);
SMimeSourceSinkAsyncTask<T> task = new SMimeSourceSinkAsyncTask<>(data, dataSource, dataSink, callback);
// don't serialize async tasks!
// http://commonsware.com/blog/2012/04/20/asynctask-threading-regression-confirmed.html
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
} else {
task.execute((Void[]) null);
}
return task;
}
项目:MVVMFrames
文件:Message.java
private void readFromParcel(Parcel source) {
what = source.readInt();
arg1 = source.readInt();
arg2 = source.readInt();
str = source.readString();
presenter = source.readString();
if (source.readInt() != 0) {
obj = source.readParcelable(getClass().getClassLoader());
}
if (source.readInt() != 0) {
objs = source.readParcelableArray(getClass().getClassLoader());
}
data = source.readBundle();
replyTo = Messenger.readMessengerOrNullFromParcel(source);
sendingUid = source.readInt();
}
项目:ArtOfAndroid
文件:MessengerActivity.java
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mService = new Messenger(service);
Message msg = Message.obtain(null, MyConstants.MSG_FROM_CLIENT);
Bundle data = new Bundle();
data.putString("msg", "Hello, this is client.");
msg.setData(data);
msg.replyTo = mGetReplyMessenger;
try {
mService.send(msg);
} catch (RemoteException e) {
e.printStackTrace();
}
}
项目:ArtOfAndroid
文件:MessengerService.java
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MyConstants.MSG_FROM_CLIENT:
Log.d(TAG, "receive msg from client: " + msg.getData().getString("msg"));
Messenger client = msg.replyTo;
Message message = Message.obtain(null, MyConstants.MSG_FROM_SERVICE);
Bundle data = new Bundle();
data.putString("reply", "Okay, your message is received, I will reply later.");
message.setData(data);
try {
client.send(message);
} catch (RemoteException e) {
e.printStackTrace();
}
break;
default:
super.handleMessage(msg);
}
}
项目:IPCCommunication
文件:ClientMsgUtils.java
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// TODO Auto-generated method stub
if (service == null) {
connect = false;
Log.d(TAG, "--- onServiceConnected failed service == null ---");
if (mConnectListener != null) {
mConnectListener.onConnected(false);
}
} else {
Log.d(TAG, "--- onServiceConnected sucessed ---");
connect = true;
if (mConnectListener != null) {
mConnectListener.onConnected(true);
}
mService = new Messenger(service);
}
}
项目:aos-MediaLib
文件:TraktService.java
public Client(Context context, Listener listener, boolean notify) {
mContext = context;
mNotify = notify;
if (listener != null) {
mListener = listener;
mHandler = new Handler(Looper.getMainLooper(), new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
if (msg.what == MSG_RESULT) {
mListener.onResult((Trakt.Result) msg.obj);
}
return false;
}
});
mMessenger = new Messenger(mHandler);
} else {
mMessenger = null;
mListener = null;
mHandler = null;
}
}
项目:letv
文件:MediaBrowserCompat.java
public void handleMessage(Message msg) {
if (this.mCallbacksMessengerRef != null) {
Bundle data = msg.getData();
data.setClassLoader(MediaSessionCompat.class.getClassLoader());
switch (msg.what) {
case 1:
this.mCallbackImpl.onServiceConnected((Messenger) this.mCallbacksMessengerRef.get(), data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), (Token) data.getParcelable(MediaBrowserProtocol.DATA_MEDIA_SESSION_TOKEN), data.getBundle(MediaBrowserProtocol.DATA_ROOT_HINTS));
return;
case 2:
this.mCallbackImpl.onConnectionFailed((Messenger) this.mCallbacksMessengerRef.get());
return;
case 3:
this.mCallbackImpl.onLoadChildren((Messenger) this.mCallbacksMessengerRef.get(), data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), data.getParcelableArrayList(MediaBrowserProtocol.DATA_MEDIA_ITEM_LIST), data.getBundle(MediaBrowserProtocol.DATA_OPTIONS));
return;
default:
Log.w(MediaBrowserCompat.TAG, "Unhandled message: " + msg + "\n Client version: " + 1 + "\n Service version: " + msg.arg1);
return;
}
}
}
项目:letv
文件:MediaBrowserCompat.java
public void onConnected() {
Bundle extras = MediaBrowserCompatApi21.getExtras(this.mBrowserObj);
if (extras != null) {
IBinder serviceBinder = BundleCompat.getBinder(extras, MediaBrowserProtocol.EXTRA_MESSENGER_BINDER);
if (serviceBinder != null) {
this.mServiceBinderWrapper = new ServiceBinderWrapper(serviceBinder);
this.mCallbacksMessenger = new Messenger(this.mHandler);
this.mHandler.setCallbacksMessenger(this.mCallbacksMessenger);
try {
this.mServiceBinderWrapper.registerCallbackMessenger(this.mCallbacksMessenger);
} catch (RemoteException e) {
Log.i(MediaBrowserCompat.TAG, "Remote error registering client messenger.");
}
onServiceConnected(this.mCallbacksMessenger, null, null, null);
}
}
}
项目:letv
文件:MediaBrowserCompat.java
public void onLoadChildren(Messenger callback, String parentId, List list, Bundle options) {
if (isCurrent(callback, "onLoadChildren")) {
List<MediaItem> data = list;
Subscription subscription = (Subscription) this.mSubscriptions.get(parentId);
if (subscription != null) {
SubscriptionCallback subscriptionCallback = subscription.getCallback(options);
if (subscriptionCallback == null) {
return;
}
if (options == null) {
subscriptionCallback.onChildrenLoaded(parentId, data);
} else {
subscriptionCallback.onChildrenLoaded(parentId, data, options);
}
}
}
}
项目:boohee_v5.6
文件:StepCounterService.java
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;
}
}
项目:LJFramework
文件:MVPMessage.java
private void readFromParcel(Parcel source) {
what = source.readInt();
arg1 = source.readInt();
arg2 = source.readInt();
str = source.readString();
presenter = source.readString();
if (source.readInt() != 0) {
obj = source.readParcelable(getClass().getClassLoader());
}
if (source.readInt() != 0) {
objs = source.readParcelableArray(getClass().getClassLoader());
}
data = source.readBundle();
replyTo = Messenger.readMessengerOrNullFromParcel(source);
sendingUid = source.readInt();
}
项目:astrobee_android
文件:AndroidRosBridgeService.java
/**
* 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);
}
}
}
项目:boohee_v5.6
文件:MediaBrowserCompat.java
public void onServiceConnected(final ComponentName name, final IBinder binder) {
postOrRun(new Runnable() {
public void run() {
if (MediaServiceConnection.this.isCurrent("onServiceConnected")) {
MediaBrowserServiceImplBase.this.mServiceBinderWrapper = new ServiceBinderWrapper(binder);
MediaBrowserServiceImplBase.this.mCallbacksMessenger = new Messenger(MediaBrowserServiceImplBase.this.mHandler);
MediaBrowserServiceImplBase.this.mHandler.setCallbacksMessenger(MediaBrowserServiceImplBase.this.mCallbacksMessenger);
MediaBrowserServiceImplBase.this.mState = 1;
try {
MediaBrowserServiceImplBase.this.mServiceBinderWrapper.connect(MediaBrowserServiceImplBase.this.mContext, MediaBrowserServiceImplBase.this.mRootHints, MediaBrowserServiceImplBase.this.mCallbacksMessenger);
} catch (RemoteException e) {
Log.w(MediaBrowserCompat.TAG, "RemoteException during connect for " + MediaBrowserServiceImplBase.this.mServiceComponent);
}
}
}
});
}
项目:pluginMVPM
文件:AsyncChannel.java
/**
* @return the SyncMessenger
*/
private static SyncMessenger obtain() {
SyncMessenger sm;
synchronized (sStack) {
if (sStack.isEmpty()) {
sm = new SyncMessenger();
sm.mHandlerThread = new HandlerThread("SyncHandler-" + sCount++);
sm.mHandlerThread.start();
sm.mHandler = sm.new SyncHandler(sm.mHandlerThread.getLooper());
sm.mMessenger = new Messenger(sm.mHandler);
} else {
sm = sStack.pop();
}
}
return sm;
}
项目:boohee_v5.6
文件:MediaBrowserCompat.java
public void handleMessage(Message msg) {
if (this.mCallbacksMessengerRef != null) {
Bundle data = msg.getData();
data.setClassLoader(MediaSessionCompat.class.getClassLoader());
switch (msg.what) {
case 1:
this.mCallbackImpl.onServiceConnected((Messenger) this.mCallbacksMessengerRef.get(), data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), (Token) data.getParcelable(MediaBrowserProtocol.DATA_MEDIA_SESSION_TOKEN), data.getBundle(MediaBrowserProtocol.DATA_ROOT_HINTS));
return;
case 2:
this.mCallbackImpl.onConnectionFailed((Messenger) this.mCallbacksMessengerRef.get());
return;
case 3:
this.mCallbackImpl.onLoadChildren((Messenger) this.mCallbacksMessengerRef.get(), data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), data.getParcelableArrayList(MediaBrowserProtocol.DATA_MEDIA_ITEM_LIST), data.getBundle(MediaBrowserProtocol.DATA_OPTIONS));
return;
default:
Log.w(MediaBrowserCompat.TAG, "Unhandled message: " + msg + "\n Client version: " + 1 + "\n Service version: " + msg.arg1);
return;
}
}
}
项目:popomusic
文件:MainActivty.java
@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.MAIN_ACTIVITY;
try {
mServiceMessenger.send(msgToService);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
项目:popomusic
文件:CollectActivity.java
@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();
}
}
}
项目:popomusic
文件:JKActivity.java
@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();
}
}
}
项目:mDL-ILP
文件:MdlApduService.java
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
if (intent.getStringExtra("type").equals("engagement")) {
mdlSim = new EngagementApduInterface(intent.getByteArrayExtra("engagementData"), 255);
} else {
final Messenger messenger = intent.getParcelableExtra("messenger");
mdlSim = new SendingHandlerApduInterface(messenger, this);
}
return super.onStartCommand(intent, flags, startId);
}
项目:AndroidActorModel
文件:Mailbox.java
/**
* create a {@link Mailbox} that handles {@link Message Messages} on the
* {@link Looper#getMainLooper() Main Looper}
*
* @param address the {@link Class} that identifies the address for this {@link Mailbox}
*/
public Mailbox(Class<?> address) {
super(Looper.getMainLooper());
this.handlerThread = null;
this.address = address;
this.messenger = new Messenger(this);
}
项目:AndroidthingsStudy
文件:BluetoothHDPActivity.java
public void onServiceConnected(ComponentName name, IBinder service) {
mHealthServiceBound = true;
Message msg = Message.obtain(null, BluetoothHDPService.MSG_REG_CLIENT);
msg.replyTo = mMessenger;
mHealthService = new Messenger(service);
try {
mHealthService.send(msg);
} catch (RemoteException e) {
Log.w(TAG, "Unable to register client to service.");
e.printStackTrace();
}
}
项目:AutoInputAuthCode
文件:AuthCode.java
/**
* 开启短信验证码获取服务
*/
private void startReadSmsService() {
mAuthcodeIntent = new Intent(mContext, ReadSmsService.class);
mAuthcodeIntent.putExtra(ReadSmsService.EXTRAS_MESSAGER, new Messenger(mHandler));
mAuthcodeIntent.putExtra(ReadSmsService.EXTRAS_COFIG, mCodeConfig);
mContext.startService(mAuthcodeIntent);
}
项目:prada
文件:UploadAgent.java
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();
}
}
}
项目:NaiveDemos
文件:BleServiceTestActivity.java
@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;
}
项目:xwallet
文件:XWalletBaseActivity.java
/**
*
* @param msg
*/
public void sendMessage(Message msg) {
if (!mBound) return;
// // Create and send a message to the service, using a supported 'what' value
// Message msg = Message.obtain(null, BlockchainService.MSG_SAY_HELLO, 0, 0);
try {
msg.replyTo = new Messenger(new ResponseHandler());
mService.send(msg);
} catch (RemoteException e) {
e.printStackTrace();
}
}
项目:letv
文件:APSService.java
public IBinder onBind(Intent intent) {
try {
String stringExtra = intent.getStringExtra("apiKey");
if (!TextUtils.isEmpty(stringExtra)) {
n.a(stringExtra);
}
this.a = new Messenger(this.b.getHandler());
return this.a.getBinder();
} catch (Throwable th) {
th.printStackTrace();
return null;
}
}
项目:astrobee_android
文件:AndroidRosBridgeService.java
/**
* @param messenger What client to send msg to
* @param typeOfMsg What type of msg is the service sending to client
* @param strToSend What String to send to client
*/
private static Message messageComposer(Messenger messenger, int typeOfMsg, String strToSend) {
// Send data as a String
Bundle bundle = new Bundle();
bundle.putString("robotResponse", strToSend);
Message msg = Message.obtain(null, typeOfMsg);
msg.setData(bundle);
return msg;
}
项目:Android_watch_magpie
文件:SensorService.java
public static Intent makeIntent(
Context context,
Class<? extends SensorHandler> sensorHandlerImpl,
Handler sensorHandler) {
Intent intent = new Intent(context, SensorService.class);
intent.setAction(START_SENSOR);
intent.putExtra(REPLY_MESSENGER, new Messenger(sensorHandler));
intent.putExtra(SENSOR_HANDLER_CLASS, sensorHandlerImpl);
return intent;
}
项目:letv
文件:MediaBrowserCompat.java
public void onLoadChildren(Messenger callback, String parentId, List list, @NonNull Bundle options) {
if (this.mCallbacksMessenger == callback) {
List<MediaItem> data = list;
Subscription subscription = (Subscription) this.mSubscriptions.get(parentId);
if (subscription != null) {
subscription.getCallback(options).onChildrenLoaded(parentId, data, options);
}
}
}
项目:boohee_v5.6
文件:MediaBrowserCompat.java
private void sendRequest(int what, Bundle data, Messenger cbMessenger) throws RemoteException {
Message msg = Message.obtain();
msg.what = what;
msg.arg1 = 1;
msg.setData(data);
msg.replyTo = cbMessenger;
this.mMessenger.send(msg);
}
项目:AndroidActorModel
文件:MessengersMapFromBundle.java
public Map<Class<?>, Messenger> apply(Bundle bundle) throws ClassNotFoundException {
if (bundle == null || bundle.isEmpty()) {
return new LinkedHashMap<>();
}
return messengersMap(bundle);
}
项目:letv
文件:MediaBrowserCompat.java
public void onConnectionFailed(Messenger callback) {
Log.e(MediaBrowserCompat.TAG, "onConnectFailed for " + this.mServiceComponent);
if (!isCurrent(callback, "onConnectFailed")) {
return;
}
if (this.mState != 1) {
Log.w(MediaBrowserCompat.TAG, "onConnect from service while mState=" + getStateLabel(this.mState) + "... ignoring");
return;
}
forceCloseConnection();
this.mCallback.onConnectionFailed();
}
项目:SlotNSlot_Android
文件:DownloadNotification.java
/**
* Called in response to onClientUpdated. Creates a new proxy and notifies
* it of the current state.
*
* @param msg the client Messenger to notify
*/
public void setMessenger(Messenger msg) {
mClientProxy = DownloaderClientMarshaller.CreateProxy(msg);
if (null != mProgressInfo) {
mClientProxy.onDownloadProgress(mProgressInfo);
}
if (mState != -1) {
mClientProxy.onDownloadStateChanged(mState);
}
}
项目:VirtualAPK
文件:MessengerActivity.java
public void onServiceConnected(ComponentName className, IBinder service) {
mService = new Messenger(service);
Log.d(TAG, "bind service");
Message msg = Message.obtain(null, MyConstants.MSG_FROM_CLIENT);
Bundle data = new Bundle();
data.putString("msg", "hello, this is client.");
msg.setData(data);
msg.replyTo = mGetReplyMessenger;
try {
mService.send(msg);
} catch (RemoteException e) {
e.printStackTrace();
}
}
项目:buildAPKsSamples
文件:BluetoothHDPActivity.java
public void onServiceConnected(ComponentName name, IBinder service) {
mHealthServiceBound = true;
Message msg = Message.obtain(null, BluetoothHDPService.MSG_REG_CLIENT);
msg.replyTo = mMessenger;
mHealthService = new Messenger(service);
try {
mHealthService.send(msg);
} catch (RemoteException e) {
Log.w(TAG, "Unable to register client to service.");
e.printStackTrace();
}
}
项目:pluginMVPM
文件:AsyncChannel.java
/**
* Connect handler to messenger. This method is typically called
* when a server receives a CMD_CHANNEL_FULL_CONNECTION request
* and initializes the internal instance variables to allow communication
* with the dstMessenger.
*
* @param srcContext
* @param srcHandler
* @param dstMessenger
*/
public void connected(Context srcContext, Handler srcHandler, Messenger dstMessenger) {
if (DBG) log("connected srcHandler to the dstMessenger E");
// Initialize source fields
mSrcContext = srcContext;
mSrcHandler = srcHandler;
mSrcMessenger = new Messenger(mSrcHandler);
// Initialize destination fields
mDstMessenger = dstMessenger;
linkToDeathMonitor();
if (DBG) log("connected srcHandler to the dstMessenger X");
}
项目:AndroidActorModel
文件:MessageSender.java
private MessageSender(int what, Messenger actorServiceMessenger,
Class<?> address, Class<?> replyToAddress) {
super(what);
this.actorServiceMessenger = actorServiceMessenger;
this.address = address;
this.replyToAddress = replyToAddress;
}
项目:boohee_v5.6
文件:ab.java
public void onCreate(Context context) {
gC = System.currentTimeMillis();
gy = context;
this.gA = ao.a();
this.gB = this.gA.getLooper();
gD = new a(this, this.gB);
this.gz = new Messenger(gD);
gD.sendEmptyMessage(0);
Log.d(ax.i, "baidu location service start1 ..." + Process.myPid());
}
项目:pluginMVPM
文件:AsyncChannel.java
/**
* Connect handler and messenger.
*
* Sends a CMD_CHANNEL_HALF_CONNECTED message to srcHandler when complete.
* msg.arg1 = status
* msg.obj = the AsyncChannel
*
* @param srcContext
* @param srcHandler
* @param dstMessenger
*/
public void connect(Context srcContext, Handler srcHandler, Messenger dstMessenger) {
if (DBG) log("connect srcHandler to the dstMessenger E");
// We are connected
connected(srcContext, srcHandler, dstMessenger);
// Tell source we are half connected
replyHalfConnected(STATUS_SUCCESSFUL);
if (DBG) log("connect srcHandler to the dstMessenger X");
}
项目:boohee_v5.6
文件:MediaBrowserCompat.java
public void onLoadChildren(Messenger callback, String parentId, List list, @NonNull Bundle options) {
if (this.mCallbacksMessenger == callback) {
List<MediaItem> data = list;
Subscription subscription = (Subscription) this.mSubscriptions.get(parentId);
if (subscription != null) {
subscription.getCallback(options).onChildrenLoaded(parentId, data, options);
}
}
}