- 1、本文档共8页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
方向传感器的应用—指北针(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
- 2025年安徽铜陵中考物理试题及答案.doc
- Unit 6 My clothes, my style 单元复习-七年级英语上册(译林版2024).pptx
- 选必1第七课 经济全球化与中国-高考政治一轮复习课件(新高考通用).pptx
- 6.3 线段的长短比较(课件)-七年级数学上册(浙教版2024).pptx
- 礼仪培训教学课件.ppt
- 4.4 角 (第2课时 角的度量)七年级数学上册(沪科版2024).pptx
- Unit 5 A healthy lifestyle 单元复习-七年级英语上册单元综合(译林版2024).pptx
- 第六课 珍惜婚姻关系-高考政治一轮复习课件(新高考通用).pptx
- 2025年安徽黄山中考语文试题及答案.doc
- 5.3一元一次方程的应用第2课时(课件)七年级数学上册(北师大版2024).pptx
文档评论(0)