android 怎么做到摇一摇唤醒应用
发布网友
发布时间:2023-09-24 13:22
我来回答
共1个回答
热心网友
时间:2024-12-02 03:38
package com.xs.test;
2
3 import android.app.Activity;
4 import android.hardware.Sensor;
5 import android.hardware.SensorEvent;
6 import android.hardware.SensorEventListener;
7 import android.hardware.SensorManager;
8 import android.os.Bundle;
9 import android.os.Handler;
10 import android.os.Message;
11 import android.os.Vibrator;
12 import android.util.Log;
13 import android.widget.Toast;
14
15 /**
16 * 安卓晃动*听--“摇一摇”
17 *
18 * @author 单红宇
19 *
20 */
21 public class TestSensorActivity extends Activity {
22
23 private SensorManager sensorManager;
24 private Vibrator vibrator;
25
26 private static final String TAG = "TestSensorActivity";
27 private static final int SENSOR_SHAKE = 10;
28
29 /** Called when the activity is first created. */
30 @Override
31 public void onCreate(Bundle savedInstanceState) {
32 super.onCreate(savedInstanceState);
33 setContentView(R.layout.main);
34 sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
35 vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
36 }