- 1、本文档共8页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
方向传感器的应用—指北针(Application of compass direction sensor)
方向传感器的应用—指北针(Application of compass direction sensor)
Look at a section of code, which is to be done in activity
Package com.zhoujt;
Import android.app.Activity;
Import android.content.Context;
Import android.hardware.Sensor;
Import android.hardware.SensorEvent;
Import android.hardware.SensorEventListener;
Import android.hardware.SensorManager;
Import android.os.Bundle;
Import android.util.Log;
Public, class, main, extends, Activity {
/ / sensor management object
SensorManager manager;
Sensor / object
Sensor sensor;
/ / interface
OrenView view;
A new sensor / event listener, rewrite the method, is mainly to rewrite onSensorChanged
SensorEventListener listener = new, SensorEventListener () {
Public, void, onSensorChanged (SensorEvent, event) {
/ / this float elaborate, is floating an array of length three, each element has a different meaning in different sensor. Because the direction sensor is used here, only the first floating-point number is concerned, that is, the angle. Moreover, this angle is relative to the degree of the North (0 in the north, clockwise in the East, 90 in the south, 180 in the West and 270 in the West)
Float orentation = event.values[0];
Log.i (####, +orentation);
This value is passed to the page will / /
View.setDegree (orentation);
}
Public void onAccuracyChanged (Sensor sensor, int accuracy) {}
};
Public, void, onCreate (Bundle, savedInstanceState) {
Super.onCreate (savedInstanceState);
/ / page object
View = new, OrenView (this);
SetContentView (view);
Get / / sensor management object
Manager = (SensorManager) this.getSystemService (Context.SENSOR_SERVICE);
Get / / sensor object, Sensor.TYPE_ORIENTATION is a static int constant, different sensors
Sensor = manager.getDefaultSensor (Sensor.TYPE_ORIENTATION);
The registration / sensor, returns a Boolean value is used to determine whether the registration is successful, determine the next step
/ / the third parameter represents the sensitivity of the sensor or refresh rate
//boolean reg =
Mana
您可能关注的文档
- 广西壮族自治区供电用电办法(Measures for power supply in the Guangxi Zhuang Autonomous Region).doc
- 庄子名句解读(Chuang-tzu famous interpretation).doc
- 库、表、约束创建以及删除(Library, table, constraint creation and deletion).doc
- 库存(Stock).doc
- 应急照明 疏散指示(Emergency lighting evacuation instructions).doc
- 庚子赔款的分配、追加及偿付(Distribution, and additional pay reparations).doc
- 度假项目集中入市 龙湖多业态应对调整管理(Holiday project concentrated into the market, Longhu multi format to respond to adjustment and management).doc
- 应用文件(Application file).doc
- 康师傅快马夺神州(The master horse from China).doc
- 广西壮族自治区预算执行情况审计监督办法(Measures for the supervision of the audit of the budget implementation of the the Guangxi Zhuang Autonomous Region).doc
文档评论(0)