当我触摸屏幕上的一个对象时,我试图使我的设备振动.我正在使用这个代码:
@H_502_8@解决方法
Vibrator v = (Vibrator) getSystemService(getApplicationContext().VIBRATOR_SERVICE); v.vibrate(300);
请尝试:
Button b = (Button) findViewById(R.id.button1); b.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v,MotionEvent event) { // TODO Auto-generated method stub Vibrator vb = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vb.vibrate(100); return false; } });
并将此权限添加到manifest.xml
<uses-permission android:name="android.permission.VIBRATE"/>