当前位置: 首页>>代码示例>>Java>>正文


Java Messenger类代码示例

本文整理汇总了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;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:24,代码来源:SMimeApi.java

示例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();
}
 
开发者ID:RockyQu,项目名称:MVVMFrames,代码行数:17,代码来源:Message.java

示例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();
    }
}
 
开发者ID:DysaniazzZ,项目名称:ArtOfAndroid,代码行数:17,代码来源:MessengerActivity.java

示例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);
    }
}
 
开发者ID:DysaniazzZ,项目名称:ArtOfAndroid,代码行数:21,代码来源:MessengerService.java

示例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);
    }
}
 
开发者ID:jiangchunyu,项目名称:IPCCommunication,代码行数:19,代码来源:ClientMsgUtils.java

示例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;
    }
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:22,代码来源:TraktService.java

示例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;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:21,代码来源:MediaBrowserCompat.java

示例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);
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:18,代码来源:MediaBrowserCompat.java

示例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);
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:18,代码来源:MediaBrowserCompat.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:24,代码来源:StepCounterService.java

示例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);
        }
    }
}
 
开发者ID:nasa,项目名称:astrobee_android,代码行数:28,代码来源:AndroidRosBridgeService.java

示例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);
                }
            }
        }
    });
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:18,代码来源:MediaBrowserCompat.java

示例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;
}
 
开发者ID:jasonwang18,项目名称:pluginMVPM,代码行数:19,代码来源:AsyncChannel.java

示例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();
        }
    }
}
 
开发者ID:popo1379,项目名称:popomusic,代码行数:16,代码来源:MainActivty.java

示例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();
        }
    }
}
 
开发者ID:popo1379,项目名称:popomusic,代码行数:16,代码来源:CollectActivity.java


注:本文中的android.os.Messenger类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。