[关闭]
@Yano 2016-01-03T18:14:32.000000Z 字数 529 阅读 1988

Android 振动

Android


Android 代码:

  1. public class MainActivity extends Activity {
  2. private Button button;
  3. private Vibrator vibrator;
  4. @Override
  5. protected void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_main);
  8. vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
  9. button = (Button) findViewById(R.id.button1);
  10. button.setOnClickListener(new View.OnClickListener() {
  11. public void onClick(View v) {
  12. vibrator.vibrate(100);
  13. }
  14. });
  15. }
  16. }

AndroidManifest 中添加权限:

  1. <uses-permission android:name="android.permission.VIBRATE" />
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注