手机版
你好,游客 登录 注册
背景:
阅读新闻

测试Android手机是否支持某种感应器

[日期:2012-01-11] 来源:Linux社区  作者:gogler [字体:大 中 小]
  

package com.gogler.ui;
import Android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;

public class AndroidUIActivity extends Activity {
 /** Called when the activity is first created. */

 private SensorManager sms;
 private CheckBox gravity,light,orientation;
 private Button check;
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  /*获取UI小组件*/
  gravity = (CheckBox) this.findViewById(R.id.gravity);
  light = (CheckBox) this.findViewById(R.id.light);
  orientation = (CheckBox) this.findViewById(R.id.orientation);
  check=(Button) this.findViewById(R.id.check);
  
  /*获取系统的传感器管理服务*/
  sms = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
  
  check.setOnClickListener(new OnClickListener(){

   @Override
   public void onClick(View v) {
    /*查询是否本机是否提供某种感应器能力*/
    if(sms.getDefaultSensor(Sensor.TYPE_ORIENTATION) != null)
     orientation.setChecked(true);
    if(sms.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null)
     gravity.setChecked(true);
    if(sms.getDefaultSensor(Sensor.TYPE_LIGHT) != null)
     light.setChecked(true);
   }
   
  });  
 
 }
}

linux
相关资讯       Android手机 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款