Android 高版(>=10)本中无法在后台震动

上方法

Vibrator mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
   long[] patern = {0,1000,1000};
    AudioAttributes audioAttributes = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            audioAttributes = new AudioAttributes.Builder()
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION) //key
                    .build();
//-1 一次震动  else  重复
            mVibrator.vibrate(pattern, -1, audioAttributes);
        }else {
            mVibrator.vibrate(pattern, -1);
        }

参考链接:https://www.jianshu.com/p/3ec9158b2041

你可能感兴趣的:(Android 高版(>=10)本中无法在后台震动)