这是代码:
public class Vibrate extends AppCompatActivity {
long[] timings = {1000, 1000, 1000, 1000};
int[] amplitudes = {0, 5, 250, 5};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vibrate);
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createWaveform(timings, amplitudes, 0));
} else {
//deprecated in API 26
v.vibrate(500);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了波形效果,但当我在 Galaxy S8 上运行它时,所有振动感觉都一样。到底是怎么回事?
振幅 5 和振幅 250 怎么可能引起相同的振动?
android android-vibration galaxy android-studio android-8.0-oreo
考虑这段代码:
int x = 99;
int * p = &x;
*p = *p + 1;
Run Code Online (Sandbox Code Playgroud)
为什么*p运算符的左侧和右侧=不同?
编译器如何知道使用左侧*p作为对象x,右侧*p作为 的值x?
具体来说,如果编译器求*p值为 的值x,为什么*p左侧的 不求值为 99,从而对文字创建错误的赋值:99 = 99 + 1;?
类似地,如果编译器求*p值为对象x(假设这是运算符的左操作数=所期望的),为什么*p右侧的值不也求值为对象x?