Call-through vibration function developed based on Android source code

Source: Internet
Author: User

When we use HTC's gxx, we will find that it has a function of vibrating prompt after it is connected. Although it is not a big function, it is more convenient to use, for example, when the call process occurs, you can place it on the table and wait for the vibration. This means that the phone is connected, and then the phone gets up and talks, so you can avoid waiting for the other party in your ear. The specific implementation is as follows. Of course, the implementation method may be different from it, but the effect is the same.

Because we are developed based on source code, we will only discuss how to add this function to phoneapp. We will not discuss independent modules or SDK-based development. Note: Modify the callpolicy. Java file in the phoneapp module.

1. Declare variables related to vibrartor:

// Call active route y vibrate <br/> private vibrator mvibrator; </P> <p> // default vibrate time <br/> Private Static final int vibrate_length = 100; <br/> private Boolean malreadyvibrate = true; 

2. Create Vibrator In the constructor:

Mvibrator = new vibrator (); 

3. Add the following code segment to the end of onphonestatechanged, that is, the GSM Branch (only supports GSM call:

If (callstate = call. state. disconnecting) {<br/> malreadyvibrate = true; <br/>} else if (malreadyvibrate & <br/> callstate = call. state. active) {<br/> // vibrate policy <br/> mvibrator. vibrate (vibrate_length); <br/> malreadyvibrate = false; <br/>} 

Note: malreadyvibrate is mainly used to prevent repeated vibration. OK. Test it ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.