Overview
The underlying hardware infrastructure that supports the basic telephone function of the OPhone system is: wireless communication module, for example, GSM/GPRS smodem), and The abstraction above it-wireless interface layer RIL: RadioInterfaceLayer) it is the soul of the related API discussed in this article. It completes the abstraction between the basic telephone function and Radio hardware, and is responsible for providing reliable data transmission, AT command sending, and command response). It is independent of the communication network and consists of two basic components: RIL Daemon) and RIL vendor dedicated implementation VendorRIL ). The former is responsible for initializing VendorRIL instances and managing calls from the application layer APIs -- converting them into "active request commands" and assigning them to VendorRIL implementation; the latter is the dedicated implementation of a specific wireless communication network, in charge of and drive the communication of the wireless network hardware module, and report the "passive Request command" to the RIL daemon to achieve network communication.
This article describes how to use APIS by calling, answering, and sending short messages.
Telephone Functions
The ophonesystem uses the built-in phone application phone.apk to call and receive calls. It provides a virtual digital keyboard to help users dial and initiate calls. When an incoming call is received, the system calls the incoming call and displays the call information prompt interface. You can call or reject the incoming call by clicking the function button on the prompt interface. But for developers, what we really care about is how to call these basic phone functions through APIS?
First, let's take a look at the call-related functions. Calling is an action initiated by the user. Therefore, it is an "active Request command". It first establishes a connection with the RIL daemon through Socket at the Java API layer and sends the Request command, the command is then forwarded to the VendorRIL implementation and the network connection of the call is established. This is the underlying principle and process. How can we implement this through APIS?
- China Mobile released OPhone SDK Based on Android technology
- How to get started with Ophone Widget SDK
- How to port a j2-api to OPhone
- Explanation of Native Development and JNI mechanism on OPhone Platform
- Guide to porting Android applications to OPhone
First, we have to start with the Intent in the OPhone system. "Intent" is used to describe and express a certain requirement or goal, for the purpose of making a call, there are two associated Intent constants available: Intent. ACTION_CALL and Intent. ACTION_DIAL, the difference is that the former will navigate to the digital dial-up keyboard, the latter directly calls, see the sample code for details:
- // Obtain the target number
- String number = editText. getText (). toString ();
- Uri data = Uri. parse ("tel:" + number );
- // Call the call Function
- If (v. getId () = R. id. btn_dial ){
- // Enter the dialing Interface
- Intent intent = new Intent (Intent. ACTION_DIAL, data );
- Intent. addCategory (Intent. CATEGORY_DEFAULT );
- StartActivity (intent );
- } Else if (v. getId () = R. id. btn_call ){
- // Call directly
- Intent intent = new Intent (Intent. ACTION_CALL, data );
- Intent. addCategory (Intent. CATEGORY_DEFAULT );
- StartActivity (intent );
- }
The code is very simple. The key is to use Intent. ACTION_DIAL or Intent. ACTION_CALL as the action name of Intent, and append the data of Uri type to Intent as the target phone number.
In addition to direct call, there is also a special requirement-capture the call Action and obtain the target phone number for further detailed handling. To achieve this, you must first understand the story behind it: In the OPhone system, there is an application type called Broadcast receiver BroadcastReceiver, it receives and processes broadcast data from a channel. The source of broadcast data can be any application in the system. For "call", the broadcast data is on the Intent. ACTION_NEW_OUTGOING_CALL channel. To listen for this action, you need to write the broadcast receiver and direct it to the above specific channel.
See the sample code:
- Public class OutgoingCallReceiver extends BroadcastReceiver {
- // Logger name
- Private static final String tag = "OutgoingCallReceiver ";
- @ Override
- Public void onReceive (Context context, Intent intent ){
- // Listen to the call and obtain the target phone number
- String name = Intent. EXTRA_PHONE_NUMBER;
- String phoneNumber = intent. getStringExtra (name );
- Log. d (tag, "Outgoing call->" + phoneNumber );
- // TODO: you code ....
- }
- }
Then, declare the broadcast receiver in the AndroidManifest. xml file:
- <receiver android:name="OutgoingCallReceiver">
- <intent-filter>
- <action android:name=
- "android.intent.action.NEW_OUTGOING_CALL"/>
- <category android:name="android.intent.category.DEFAULT"/>
- </intent-filter>
- </receiver>
Action. name points to the string literal value of the constant Intent. ACTION_NEW_OUTGOING_CALL. When dialing again, the receiver automatically captures and obtains the target phone number, whether using the API described above or using the built-in phone application.
Further consideration is given to the assumption that a specific number needs to be blocked-the user is forbidden to call the number. How can this problem be solved? In fact, you only need to terminate broadcast data transmission in the implementation code of the broadcast receiver. See the sample code:
- // Do not call [139999999 ].
- String target = "139999999 ";
- If (phoneNumber. inclusignorecase (target )){
- // Terminate the spread of Broadcast Data
- AbortBroadcast ();
- // Display prompt information
- String msg = "number [" + target + "] forbidden ~! ";
- Toast. makeText (context, msg, Toast. LENGTH_LONG). show ();
- }
Note that not all broadcasts can be terminated. Only ordered broadcast Orderedbroadcasts can be terminated. What is ordered broadcast?