8.1 安卓系统层实现人体感应功能

第一步:接收开机广播,启动人体感应服务

第二步:在服务BodyInductionService.java中处理人体感应,读取人体感应值/sys/devices/virtual/adw/adwdev/adwgpio1 ,读取到0为有人,1为没人;有人经过时唤醒设备,没人时30秒后休眠屏幕

BodyInductionService.java

    /***method: onHandleIntent()  创建服务   /sys/class/gpio/gpio39/value  *@author qhj by 20200309*/@Overrideprotected void onHandleIntent(Intent arg0) {String bl_data = "1024";Log.i(TAG, "BodyInductionService-->onHandleIntent()------ by qhj");   while(bootBodyInductionServiceflag){int body_induction = 1;Log.i(TAG,"------------body_induction=="+body_induction);String body_value = adw_read_file("/sys/devices/virtual/adw/adwdev/adwgpio1");Log.i(TAG,"------------body_value=="+body_value);if(body_value.equals("0") && body_induction != 0 ){Intent wakeupIntent = new Intent();wakeupIntent.setAction("android.adw.intent.action.wakeup");wakeupIntent.addFlags(0x01000000);sendBroadcast(wakeupIntent);sleepScreen(body_induction);Log.i(TAG,"-----------body_induction!=0_start wakeup!!!");}else if(body_induction == 0){if (timer != null) {timer.cancel();timer = null;}if (task != null) {task.cancel();task = null;}Log.i(TAG,"-----------body_induction==0 cancel task!!!");}else if(body_value.equals("1")&& body_induction != 0){Log.i(TAG,"-----------body_induction!=0_body_value==0 no do!!!");}SystemClock.sleep(1000);}         }/***  无人时定时休眠 *  by qhj  20200309*/public void sleepScreen(int time_induction) {if (timer == null) {timer = new Timer();} else {timer.cancel();timer = null;timer = new Timer();}if (task == null) {task = new TimerTask() {public void run() {Log.d("SVVV","--------------The_Device_is_Going_sleep___1111!!!");//isWakeDemoKey = true;PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);pm.goToSleep(SystemClock.uptimeMillis());}};} else {task.cancel();task = null;task = new TimerTask() {public void run() {Log.d(TAG,"--------------The_Device_is_Going_sleep___2222!!!");//isWakeDemoKey = true;PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);pm.goToSleep(SystemClock.uptimeMillis());}};}Log.d(TAG,"--------time_induction==ms=="+time_induction * 30 * 1000);Date delay = new Date(System.currentTimeMillis() + time_induction * 30 * 1000);if (timer != null && task != null) {timer.schedule(task, delay);}} /** 读取设备节点内容.*/private static String adw_read_file(String path){String data = "1024";// 默认值BufferedReader reader = null;try {reader = new BufferedReader(new FileReader(path));data = reader.readLine();} catch (IOException e) {e.printStackTrace();} finally {if (reader != null) {try {reader.close();} catch (IOException e) {e.printStackTrace();}}}return data;}

注:唤醒是封装的广播接口

                         Intent wakeupIntent = new Intent();wakeupIntent.setAction("android.adw.intent.action.wakeup");wakeupIntent.addFlags(0x01000000);sendBroadcast(wakeupIntent);


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部