我有一个小问题。
按下按钮时,我的应用程序必须振动,在我的三星 S3(API 17)中一切正常,但在我的 S2(API 15)上,这不起作用。
编码:
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.VIBRATE"/>
主要的
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Vibrator x = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
x.cancel();
backgroundVibrate = 0;
//final ToggleButton toggle = (ToggleButton)findViewById(R.id.toggleButton1);
setContentView(R.layout.activity_fullscreen);
Button fast1 = (Button) findViewById(R.id.fast1);
fast1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
long[] pattern = { 0, 100, 300 };
vibrate(pattern, false);
}
});
public void vibrate(long[] pattern, boolean stop)
{
// Get instance of Vibrator from current Context
Vibrator x = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (stop == false)
{
x.vibrate(pattern, 0);
currentVibrate = true;
System.out.println("vibrate ON");
}
if (stop == true)
{
x.cancel();
currentVibrate = false;
}
}
有人有想法吗?
谢谢