@Yano
2016-01-03T18:14:32.000000Z
字数 529
阅读 1969
Android
Android 代码:
public class MainActivity extends Activity {
private Button button;
private Vibrator vibrator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
vibrator.vibrate(100);
}
});
}
}
AndroidManifest 中添加权限:
<uses-permission android:name="android.permission.VIBRATE" />