Define a Client Messenger associated with the Handler to receive the return from the server:
/** Target we publish for clients to send messages to IncomingHandler.*/finalMessenger mMessenger =newMessenger(new IncomingHandler());/* * Start cellular network operator querying. * @param event the event you want to start, can be one of following: * 1 - EVENT_NETWORK_SCAN * 2 - EVENT_NETWORK_SELECT * @return mMessenger which associated with Handler.*/Message msg =Message.obtain(null,1/ event /,0/ slot */,0);msg.replyTo= mMessenger;mService.send(msg);/** Receive the return of the network operator's search interface:*/finalString[] scanInfo =msg.getData().getStringArray("result");for (int i =0; i <scanInfo.length; i++) {String item[] = scanInfo[i].split(",");String operatorAlphaLong = scanInfo0; // such as 'CHN-UNICOM'String operatorAlphaShort = scanInfo1; // such as 'UNICOM'String operatorNumeric = scanInfo2; // such as '46001'String stateString = scanInfo3; // such as 'available/forbidden'}/** Set cellular network operator. * @param event the event you want to start, can be one of following: * 1 - EVENT_NETWORK_SCAN * 2 - EVENT_NETWORK_SELECT * @return mMessenger which associated with Handler.*/Bundle bundle =newBundle();bundle.putString("operatorAlphaLong", operatorAlphaLong);bundle.putString("operatorAlphaShort", operatorAlphaShort);bundle.putString("operatorNumeric", operatorNumeric);bundle.putString("stateString", stateString);Message msg =Message.obtain(null,2/ event /,0/ slot */,0, bundle);msg.replyTo= mMessenger;mService.send(msg);/** Return of the interface set:*/String responce ="Registration Done";switch (msg.arg1) {case-1:responce ="Not Allowed";break;case-2:responce ="Please connect later";break;}@OverridepublicvoidonServiceConnected(ComponentName name,IBinder service) {// Messenger for communicating with serviceMessenger mService =newMessenger(service);}};