Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set the mobile phone to vibrate when the call is connected and disconnected in Android

Shulou Source: shulou.com Published: 2022-06-02 12:17:11 09月19日 Update

This article is about how to set your phone to vibrate when a call is connected and disconnected in Android. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

[Android Version]

Android V2.3 (GB,GB2)

Android v4.0,4.1 (ICS, ICS2, JB)

Android V4.2 (JB2,JB3,JB5)

Android V4.4

Android V5.0,5.1

[DESCRIPTION]

If you need to customize the behavior that the phone vibrates when the call is connected or disconnected, you can refer to the following modifications

[SOLUTION]

When the call is connected:

Versions prior to Android V4.4:

1 add private Vibrator mVibrator at the beginning of packages\ apps\ phone\ src\ com\ android\ phone\ CallNotifier.java

2 add at the beginning of the packages\ apps\ phone\ src\ com\ android\ phone\ CallNotifier.java function onPhoneStateChanged

If (mVibrator = = null) {

MVibrator = (Vibrator)

MApplication.getApplicationContext () getSystemService (Context.VIBRATOR_SERVICE)

}

3 add a member variable to packages\ apps\ phone\ src\ com\ android\ phone\ CallNotifier.java

Call.State mLastCallState = Call.State.IDLE

Then add the following code to the statement Phone fgPhone = mCM.getFgPhone (); in the function onPhoneStateChanged

Call.State ringCallState =

MCM.getRingingPhone (). GetRingingCall (). GetState ()

Call.State fgCallState = mCM.getActiveFgCallState ()

If ((ringCallState==Call.State.IDLE & & mLastCallState.isRinging ()) | | / / MT

(fgCallState==Call.State.ACTIVE & & mLastCallState.isDialing ()) / / MO

{

/ / here means that call is connected

Final int MO_CALL_VIBRATE_TIME = 300; / / msec

MVibrator.vibrate (MO_CALL_VIBRATE_TIME)

}

MLastCallState = ringCallState.isRinging ()? RingCallState:fgCallState

MtkAndroid V4.4 and later:

This feature is already available.

After hanging up:

In CallNotifier.java onDisconnect ()

Phone.State state = mCM.getState (); add the following Code

If (mVibrator = = null) {

MVibrator = (Vibrator)

MApplication.getApplicationContext () getSystemService (Context.VIBRATOR_SERVICE)

}

Final int CALL_DISC_VIBRATE_TIME = 300; / / msec

MVibrator.vibrate (CALL_DISC_VIBRATE_TIME)

Thank you for reading! This is the end of the article on "how to set the phone to vibrate when the call is connected and disconnected in Android". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Mobile phone when on vibrate content function beginning more version article reference good practical code function variable member article see knowledge if Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei vpn Shulou Technology Apple