android.os.Messenger Java Examples
The following examples show how to use
android.os.Messenger.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NTrip.java From api-ntrip-java-client with MIT License | 7 votes |
public void onServiceConnected(ComponentName className, IBinder service) { mService = new Messenger(service); try { //Register client with service Message msg = Message.obtain(null, NTRIPService.MSG_REGISTER_CLIENT); msg.replyTo = mMessenger; mService.send(msg); //Request a status update. msg = Message.obtain(null, NTRIPService.MSG_UPDATE_STATUS, 0, 0); mService.send(msg); //Request full log from service. msg = Message.obtain(null, NTRIPService.MSG_UPDATE_LOG_FULL, 0, 0); mService.send(msg); SetSettings(); NTrip.this.onServiceConnected(); } catch (RemoteException e) { // In this case the service has crashed before we could even do anything with it } }
Example #2
Source File: ServiceConnector.java From microbit with Apache License 2.0 | 6 votes |
public void onServiceConnected(ComponentName className, IBinder service) { // This is called when the connection with the service has been // established, giving us the object we can use to // interact with the service. We are communicating with the // service using a Messenger, so here we get a client-side // representation of that from the raw IBinder object. Messenger mServiceMessenger = new Messenger(service); mServiceMessengers.put(className.getClassName(), mServiceMessenger); if(++countBoundServices == COUNT_SERVICES_FOR_BINDING) { ConnectedDevice connectedDevice = BluetoothUtils.getPairedMicrobit(mCtx); if(connectedDevice.mStatus) { Intent intent = new Intent(mCtx, IPCService.class); intent.putExtra(IPCConstants.INTENT_TYPE, EventCategories.IPC_BLE_CONNECT); mCtx.startService(intent); } } mBound = true; }
Example #3
Source File: NetworkAgentInfo.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, Network net, NetworkInfo info, LinkProperties lp, NetworkCapabilities nc, int score, Context context, Handler handler, NetworkMisc misc, NetworkRequest defaultRequest, ConnectivityService connService) { this.messenger = messenger; asyncChannel = ac; network = net; networkInfo = info; linkProperties = lp; networkCapabilities = nc; currentScore = score; mConnService = connService; mContext = context; mHandler = handler; networkMonitor = mConnService.createNetworkMonitor(context, handler, this, defaultRequest); networkMisc = misc; }
Example #4
Source File: MediaBrowserCompat.java From letv with Apache License 2.0 | 6 votes |
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); } } } }
Example #5
Source File: GSAServiceClient.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override public void onServiceConnected(ComponentName name, IBinder service) { // Ignore this call if we disconnected in the meantime. if (mContext == null) return; mService = new Messenger(service); mComponentName = name; try { Message registerClientMessage = Message.obtain( null, REQUEST_REGISTER_CLIENT); registerClientMessage.replyTo = mMessenger; Bundle b = mGsaHelper.getBundleForRegisteringGSAClient(mContext); registerClientMessage.setData(b); registerClientMessage.getData().putString( KEY_GSA_PACKAGE_NAME, mContext.getPackageName()); mService.send(registerClientMessage); // Send prepare overlay message if there is a pending GSA context. } catch (RemoteException e) { Log.w(SERVICE_CONNECTION_TAG, "GSAServiceConnection - remote call failed", e); } }
Example #6
Source File: BluetoothHelper.java From bleYan with GNU General Public License v2.0 | 6 votes |
@Override public void onServiceConnected(ComponentName name, IBinder service) { BleLog.i(TAG, "mConnection onServiceConnected"); mSendMessage = new Messenger(service); sendMsgAndSubscribe(BleConstants.MSG_CONTROL_ID_REGISTER); mConnectTimeout = new TimeoutCallback() { @Override public void onTimeout() { if(mConnCallback != null) { mConnCallback.onConnectFailed(ConnectError.ConnectTimeout); } stopScanDevice(); } }; if(mBindListener != null){ mBindListener.onServiceConnected(); } }
Example #7
Source File: DownloaderClientMarshaller.java From UnityOBBDownloader with Apache License 2.0 | 6 votes |
@Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_ONDOWNLOADPROGRESS: Bundle bun = msg.getData(); if ( null != mContext ) { bun.setClassLoader(mContext.getClassLoader()); DownloadProgressInfo dpi = (DownloadProgressInfo) msg.getData() .getParcelable(PARAM_PROGRESS); mItf.onDownloadProgress(dpi); } break; case MSG_ONDOWNLOADSTATE_CHANGED: mItf.onDownloadStateChanged(msg.getData().getInt(PARAM_NEW_STATE)); break; case MSG_ONSERVICECONNECTED: mItf.onServiceConnected( (Messenger) msg.getData().getParcelable(PARAM_MESSENGER)); break; } }
Example #8
Source File: StepService.java From JkStepSensor with Apache License 2.0 | 6 votes |
@Override public void handleMessage(Message msg) { switch (msg.what) { case Constant.MSG_FROM_CLIENT: try { // 缓存数据 cacheStepData(StepService.this,StepDcretor.CURRENT_STEP + ""); // 更新通知栏 updateNotification(msg.getData()); // 回复消息给Client Messenger messenger = msg.replyTo; Message replyMsg = Message.obtain(null, Constant.MSG_FROM_SERVER); Bundle bundle = new Bundle(); bundle.putInt(STEP_KEY, StepDcretor.CURRENT_STEP); replyMsg.setData(bundle); messenger.send(replyMsg); } catch (RemoteException e) { e.printStackTrace(); } break; default: super.handleMessage(msg); } }
Example #9
Source File: MessengerService.java From astrobee_android with Apache License 2.0 | 6 votes |
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; }
Example #10
Source File: MediaBrowserCompat.java From letv with Apache License 2.0 | 6 votes |
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); } } } }); }
Example #11
Source File: DownloaderClientMarshaller.java From Alite with GNU General Public License v3.0 | 6 votes |
@Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_ONDOWNLOADPROGRESS: Bundle bun = msg.getData(); if ( null != mContext ) { bun.setClassLoader(mContext.getClassLoader()); DownloadProgressInfo dpi = (DownloadProgressInfo) msg.getData() .getParcelable(PARAM_PROGRESS); mItf.onDownloadProgress(dpi); } break; case MSG_ONDOWNLOADSTATE_CHANGED: mItf.onDownloadStateChanged(msg.getData().getInt(PARAM_NEW_STATE)); break; case MSG_ONSERVICECONNECTED: mItf.onServiceConnected( (Messenger) msg.getData().getParcelable(PARAM_MESSENGER)); break; } }
Example #12
Source File: DownloaderClientMarshaller.java From travelguide with Apache License 2.0 | 6 votes |
@Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_ONDOWNLOADPROGRESS: Bundle bun = msg.getData(); if ( null != mContext ) { bun.setClassLoader(mContext.getClassLoader()); DownloadProgressInfo dpi = (DownloadProgressInfo) msg.getData() .getParcelable(PARAM_PROGRESS); mItf.onDownloadProgress(dpi); } break; case MSG_ONDOWNLOADSTATE_CHANGED: mItf.onDownloadStateChanged(msg.getData().getInt(PARAM_NEW_STATE)); break; case MSG_ONSERVICECONNECTED: mItf.onServiceConnected( (Messenger) msg.getData().getParcelable(PARAM_MESSENGER)); break; } }
Example #13
Source File: RegisteredMediaRouteProvider.java From cwac-mediarouter with Apache License 2.0 | 6 votes |
@Override public void onServiceConnected(ComponentName name, IBinder service) { if (DEBUG) { Log.d(TAG, this + ": Connected"); } if (mBound) { disconnect(); Messenger messenger = (service != null ? new Messenger(service) : null); if (isValidRemoteMessenger(messenger)) { Connection connection = new Connection(messenger); if (connection.register()) { mActiveConnection = connection; } else { if (DEBUG) { Log.d(TAG, this + ": Registration failed"); } } } else { Log.e(TAG, this + ": Service returned invalid messenger binder"); } } }
Example #14
Source File: MediaRouteProviderService.java From cwac-mediarouter with Apache License 2.0 | 6 votes |
private boolean onSelectRoute(Messenger messenger, int requestId, int controllerId) { ClientRecord client = getClient(messenger); if (client != null) { MediaRouteProvider.RouteController controller = client.getRouteController(controllerId); if (controller != null) { controller.onSelect(); if (DEBUG) { Log.d(TAG, client + ": Route selected" + ", controllerId=" + controllerId); } sendGenericSuccess(messenger, requestId); return true; } } return false; }
Example #15
Source File: FanfouServiceManager.java From fanfouapp-opensource with Apache License 2.0 | 5 votes |
public static void doFriendshipsExists(final Context context, final String userA, final String userB, final Handler handler) { final Intent intent = new Intent(context, FanFouService.class); intent.putExtra(Constants.EXTRA_TYPE, Constants.TYPE_FRIENDSHIPS_EXISTS); intent.putExtra("user_a", userA); intent.putExtra("user_b", userB); intent.putExtra(Constants.EXTRA_MESSENGER, new Messenger(handler)); context.startService(intent); }
Example #16
Source File: CbApi.java From PressureNet-SDK with MIT License | 5 votes |
/** * Make an API call and store the results * * @return */ public long makeStatsAPICall(CbStatsAPICall call, CbService caller, Messenger ms) { this.replyResult = ms; this.caller = caller; StatsDataDownload api = new StatsDataDownload(); api.setReplyToApp(ms); api.setApiCall(call); api.execute(""); return System.currentTimeMillis(); }
Example #17
Source File: ScanningMediaService.java From letv with Apache License 2.0 | 5 votes |
public int onStartCommand(Intent intent, int flags, int startId) { if (intent == null) { LogInfo.log("onStartCommand", "intent == null>>"); return super.onStartCommand(intent, flags, startId); } switch (intent.getIntExtra("cmd", 0)) { case 1: this.messenger = (Messenger) intent.getParcelableExtra("handler"); this.mScannerLocalVideoAsync = new LocalVideoScannerThread(this); this.mScannerLocalVideoAsync.start(); break; case 2: if (this.mScannerLocalVideoAsync != null) { this.mScannerLocalVideoAsync.cancelTask(true); this.mScannerLocalVideoAsync = null; } stopSelf(); break; case 3: String tip = intent.getStringExtra("tip"); LogInfo.log(" ", "showToast tip >>" + tip); LetvToast.showToast(tip); break; } return super.onStartCommand(intent, flags, startId); }
Example #18
Source File: MainActivity.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void onClick(View view) { Intent intent = new Intent(this, DownloadService.class); // Create a new Messenger for the communication back Messenger messenger = new Messenger(handler); // TODO put messages into the intent intent.putExtra("MESSENGER", messenger); intent.setData(Uri.parse("http://www.vogella.de/index.html")); intent.putExtra("urlpath", "http://www.vogella.de/index.html"); startService(intent); }
Example #19
Source File: RemoteService.java From AndroidAll with Apache License 2.0 | 5 votes |
@Override public void handleMessage(@NonNull android.os.Message msg) { super.handleMessage(msg); Bundle bundle = msg.getData(); // Class not found when unmarshalling: com.chiclaim.ipc.bean.Message bundle.setClassLoader(Message.class.getClassLoader()); Message data = bundle.getParcelable("message"); Toast.makeText(getApplicationContext(), data.getContent(), Toast.LENGTH_SHORT).show(); Messenger replyTo = msg.replyTo; Message raw = new Message(); raw.setContent("I receive your message: " + data.getContent()); android.os.Message message = new android.os.Message(); Bundle replyBundle = new Bundle(); replyBundle.putParcelable("message", raw); message.setData(replyBundle); try { replyTo.send(message); } catch (RemoteException e) { e.printStackTrace(); } }
Example #20
Source File: PoAServiceConnectorImpl.java From asf-sdk with GNU General Public License v3.0 | 5 votes |
@Override public void onServiceConnected(ComponentName className, IBinder service) { serviceMessenger = new Messenger(service); isBound = true; // send the pending messages that may have been added to the list before the bind was complete sendPendingMessages(); }
Example #21
Source File: BaseActivity.java From your-local-weather with GNU General Public License v3.0 | 5 votes |
public void onServiceConnected(ComponentName className, IBinder binderService) { weatherForecastService = new Messenger(binderService); weatherForecastServiceLock.lock(); try { while (!weatherForecastUnsentMessages.isEmpty()) { weatherForecastService.send(weatherForecastUnsentMessages.poll()); } } catch (RemoteException e) { appendLog(getBaseContext(), TAG, e.getMessage(), e); } finally { weatherForecastServiceLock.unlock(); } }
Example #22
Source File: VerifiedHandler.java From delion with Apache License 2.0 | 5 votes |
@Override public boolean sendMessageAtTime(Message msg, long uptimeMillis) { Messenger client = msg.replyTo; if (!mClientTrustMap.containsKey(client)) mClientTrustMap.put(client, checkCallerIsValid()); if (!mClientTrustMap.get(client)) return false; return super.sendMessageAtTime(msg, uptimeMillis); }
Example #23
Source File: AbstractAppJob.java From your-local-weather with GNU General Public License v3.0 | 5 votes |
public void onServiceConnected(ComponentName className, IBinder binderService) { currentWeatherService = new Messenger(binderService); currentWeatherServiceLock.lock(); try { while (!currentWeatherUnsentMessages.isEmpty()) { currentWeatherService.send(currentWeatherUnsentMessages.poll()); } } catch (RemoteException e) { appendLog(getBaseContext(), TAG, e.getMessage(), e); } finally { currentWeatherServiceLock.unlock(); } serviceConnected(currentWeatherServiceConnection); }
Example #24
Source File: ServiceConnector.java From microbit with Apache License 2.0 | 5 votes |
public ServiceConnector(Context ctx) { mCtx = ctx; handlerThread = new HandlerThread("IPChandlerThread"); handlerThread.start(); handler = new IncomingHandler(handlerThread); mClientMessenger = new Messenger(handler); }
Example #25
Source File: FanfouServiceManager.java From fanfouapp-opensource with Apache License 2.0 | 5 votes |
public static void doProfile(final Context context, final String userId, final Handler handler) { final Intent intent = new Intent(context, FanFouService.class); intent.putExtra(Constants.EXTRA_TYPE, Constants.TYPE_USERS_SHOW); intent.putExtra(Constants.EXTRA_ID, userId); intent.putExtra(Constants.EXTRA_MESSENGER, new Messenger(handler)); context.startService(intent); }
Example #26
Source File: FanfouServiceManager.java From fanfouapp-opensource with Apache License 2.0 | 5 votes |
public static void doFetchUserTimeline(final Context context, final Messenger messenger, final String userId, final String sinceId, final String maxId) { FanfouServiceManager.doFetchTimeline(context, Constants.TYPE_STATUSES_USER_TIMELINE, messenger, 0, userId, sinceId, maxId); }
Example #27
Source File: MessengerUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
@Override public void onServiceConnected(ComponentName name, IBinder service) { Log.d("MessengerUtils", "client service connected " + name); mServer = new Messenger(service); int key = UtilsBridge.getCurrentProcessName().hashCode(); Message msg = Message.obtain(mReceiveServeMsgHandler, WHAT_SUBSCRIBE, key, 0); msg.replyTo = mClient; try { mServer.send(msg); } catch (RemoteException e) { Log.e("MessengerUtils", "onServiceConnected: ", e); } sendCachedMsg2Server(); }
Example #28
Source File: ShowLyrics.java From Lyrically with MIT License | 5 votes |
@Override protected void onHandleIntent(Intent intent) { Messenger messenger = (Messenger) intent.getExtras().get("messenger"); try { messenger.send(new Message()); } catch (RemoteException e) { e.printStackTrace(); } }
Example #29
Source File: WalkingActivity.java From Running with Apache License 2.0 | 5 votes |
@Override public void onServiceConnected(ComponentName name, IBinder service) { try { messenger = new Messenger(service); Message msg = Message.obtain(null,Constant.Config.MSG_FROM_CLIENT); msg.replyTo = mGetReplyMessenger; messenger.send(msg); } catch (RemoteException e) { e.printStackTrace(); } }
Example #30
Source File: InstrumentationConnectionTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void verifyDupClientRegAddsOnlyOne() throws InterruptedException { instrumentationConnection.init(mockedInstrumentation, mockedFinisher); IncomingHandler incomingHandler = instrumentationConnection.incomingHandler; // Create clients Messenger client1 = new Messenger(new Handler(Looper.getMainLooper())); String clientType = "3"; // register clients instrumentationConnection.registerClient(clientType, client1); instrumentationConnection.registerClient(clientType, client1); instrumentationConnection.registerClient(clientType, client1); // wait for all messages to be handled waitForMsgHandling(incomingHandler); // ensure TypedClient list contain all clients assertEquals(1, incomingHandler.typedClients.size()); assertEquals(1, incomingHandler.typedClients.get(clientType).size()); assertTrue(incomingHandler.typedClients.get(clientType).contains(client1)); // un-register only client1 instrumentationConnection.unregisterClient(clientType, client1); waitForMsgHandling(incomingHandler); // ensure all client1 is gone assertEquals(0, incomingHandler.typedClients.size()); assertNull(incomingHandler.typedClients.get(clientType)); instrumentationConnection.terminate(); assertNull(instrumentationConnection.incomingHandler); }