本文整理匯總了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();
}
}
}