本文整理汇总了Java中android.os.Messenger类的典型用法代码示例。如果您正苦于以下问题:Java Messenger类的具体用法?Java Messenger怎么用?Java Messenger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Messenger类属于android.os包,在下文中一共展示了Messenger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeApiAsync
import android.os.Messenger; //导入依赖的package包/类
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;
}
示例2: readFromParcel
import android.os.Messenger; //导入依赖的package包/类
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();
}
示例3: onServiceConnected
import android.os.Messenger; //导入依赖的package包/类
@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();
}
}
示例4: handleMessage
import android.os.Messenger; //导入依赖的package包/类
@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);
}
}
示例5: onServiceConnected
import android.os.Messenger; //导入依赖的package包/类
@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);
}
}
示例6: Client
import android.os.Messenger; //导入依赖的package包/类
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;
}
}
示例7: handleMessage
import android.os.Messenger; //导入依赖的package包/类
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;
}
}
}
示例8: onConnected
import android.os.Messenger; //导入依赖的package包/类
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);
}
}
}
示例9: onLoadChildren
import android.os.Messenger; //导入依赖的package包/类
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);
}
}
}
}
示例10: 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;
}
}
示例11: 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);
}
}
}
示例12: onServiceConnected
import android.os.Messenger; //导入依赖的package包/类
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);
}
}
}
});
}
示例13: obtain
import android.os.Messenger; //导入依赖的package包/类
/**
* @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;
}
示例14: 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.MAIN_ACTIVITY;
try {
mServiceMessenger.send(msgToService);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
示例15: 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();
}
}
}