简体   繁体   中英

How does android perform a feedback haptic on physical button?

After checking android source code, I knew the when a button perform click it will call the view's performHapticFeedback methor so that the phone will perform a BZZZTT effect. the performHapticFeedback code is like:

public boolean performHapticFeedback(int feedbackConstant, int flags) {
    if (mAttachInfo == null) {
        return false;
    }
    //noinspection SimplifiableIfStatement
    if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0
            && !isHapticFeedbackEnabled()) {
        return false;
    }
    return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant,
            (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0);
}

But, I wonder how android performs a feedback haptic on physical button (such as key_home,key_Back,key_menu). cause the physical button doesn't base on View. I have searched the source code for a whole afternoon but I got nothing valuable code lines about how physical button performs Haptic Feedback~~~~ Can anyone give me some tips?

Thanks

The relative code lines are found in PhoneWindowManager.java -> public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) .(which is called before the other uplever apps can handle); After judging on KeyEvent code, then it will call the mVibrator.vibrate(pattern[0]); in which the mVibrator is got by calling mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM