Set Network Operators API

Permission

The application declares the following permissions in the manifest:

 android.permission.CLOUDPOS_SET_CELLULAR_NETWORK_OPERATOR

Description

  • Bind Service

bindService(new Intent().setClassName("com.smartpos.phone.settings", "com.smartpos.phone.settings.RadioQueryService"), mQueryRadioNetworkConnection, Context.BIND_AUTO_CREATE);
  • Use the IBinder returned by the service to construct the communication Messenger

private ServiceConnection mQueryRadioNetworkConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
  • 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.
*/
final Messenger mMessenger = new Messenger(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:*/
final String[] 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 = new Bundle();
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;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// Messenger for communicating with service
Messenger mService = new Messenger(service);
}
};

Sample code

Last updated