参考:
android手机旋转方向识别

gitee代码链接:
检测手机旋转角度

代码极其简单,而且不需要配置 AndroidManifest.xml。

package com.example.detectorientation;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;
import android.util.Log;
import android.view.OrientationEventListener;public class MainActivity extends AppCompatActivity {private String TAG = "MainActivity";private OrientationEventListener mOrientationListener;private final void startOrientationChangeListener() {mOrientationListener = new OrientationEventListener(this) {@Overridepublic void onOrientationChanged(int rotation) {Log.e(TAG, " " + rotation);// 当 rotation = -1 时,表示手机是 水平 放置的!!!}};mOrientationListener.enable();}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);startOrientationChangeListener();}
}


Called when the orientation of the device has changed. orientation parameter is in degrees, ranging from 0 to 359. orientation is 0 degrees when the device is oriented in its natural position, 90 degrees when its left side is at the top, 180 degrees when it is upside down, and 270 degrees when its right side is to the top. ORIENTATION_UNKNOWN is returned when the device is close to flat and the orientation cannot be determined.
Params:
orientation – The new orientation of the device.
See Also:
ORIENTATION_UNKNOWN
abstract public void onOrientationChanged(int orientation);

Android 监听手机旋转角度相关推荐

  1. android 监听手机电量变化

    今天,简单讲讲如何监听手机电量的变化. 监听电量是不能静态注册的. 后来上网搜索,发现有五个不能静态注册的广播,这里记录一下,免得下次再后知后觉的发现并惊讶于自己的笨拙. 不能静态注册的广播: and ...

  2. android 监听手机开机

    今天,简单讲讲  android 监听手机开机. 需求描述:有些时候,我们需要我们的程序在开机后能自动运行,在系统即将关闭时,能写入一些记录到指定的文件里. 一.开机广播监听: Android系统 ...

  3. Android监听手机网络变化

    Android监听手机网络变化 手机网络状态发生变化会发送广播,利用广播接收者,监听手机网络变化 效果图 注册广播接收者 <?xml version="1.0" encodi ...

  4. Android监听手机短信

    Android监听手机短信的方法有两种,分别为: 1.接受系统的短信广播:当手机收到新消息时,会发送一条广播,通过该广播就可以获取短信内容: 2.监听短信数据库:利用观察者模式监听短信数据库,当短信数 ...

  5. Android监听手机返回键

    Android在做项目时,有时候点击返回按钮没反应(有冲突),那就需要我们监听返回键.重写onKeyDown()方法: // 监听手机返回键 @Override public boolean onKe ...

  6. Android 监听手机GPS打开状态

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/70854942 本文出自[赵彦军的博客] GPS_Presenter package ...

  7. android 监听手机屏幕唤醒和睡眠广播

    最近做APP要做一个android 手机屏幕唤醒和睡眠的监听. 但发现下面问题: 我想获取调用屏幕打开时应用.在我 AndroidManifest.xml 已经指定:android.intent.ac ...

  8. Android 监听手机按下Home键

    系统本身有这个广播,只需要监听这个广播就可以了! private BroadcastReceiver mHomeKeyEventReceiver = new BroadcastReceiver() { ...

  9. Android监听手机软键盘的弹起和关闭

    在很多App开发过程中需要在Activity中监听Android设备的软键盘弹起与关闭,但是Android似乎没有提供相关的的监听API给我们来调用,本文提供了一个可行的办法来监听软键盘的弹起与关闭. ...

最新文章

  1. phpcms的安装以及简单使用
  2. jackson (json、xml的序列化与反序列化)
  3. Python学习入门基础教程(learning Python)--3.3.3 Python逻辑关系表达式
  4. Ie6下asp.net 中treeview自动随鼠标变小的修复
  5. 互联网企业安全之端口监控
  6. 数学C语言编程,数学规划 (最速下降法,c语言编程).doc
  7. html 收藏功能,用react怎么实现收藏功能?
  8. 【JVM】类是怎么加载的?
  9. 第 26 章 职责链模式
  10. 如何通过C#开发一个媒体播放器(中)
  11. dev gridcontrol 单选框效果
  12. 【转】每天一个linux命令(11):nl命令
  13. canvas 文字垂直居中
  14. 万能地图下载器标绘线的参数说明
  15. winpe加载raid_winpe集成raid驱动~
  16. wgs84坐标系拾取工具_百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换的工具...
  17. 计算机共享网络的账号密码怎么设置密码,win10局域网共享怎么设置账号密码
  18. python数据分析热力图怎么看_数据分析实战—热力图
  19. WordPress XMLRPC安全漏洞
  20. 深入了解戴维斯双击和戴维斯双杀

热门文章

  1. 高校新闻抓取分析之百度新闻篇---数据抓取
  2. 计算机没有外审的核心期刊,国内核心期刊投稿经验总结战友们共同分享丁香园论坛...
  3. HAUT 1261 地狱飞龙(数值积分)(河南工业大学2017校赛)
  4. 区块链 试题_区块链金融-中国大学mooc-试题题目及答案
  5. 腾讯地图api php经纬度转换地址,腾讯地图经纬度转换为百度地图经纬度
  6. ipadmobile通用webapp框架前哨战
  7. 使用c语言计算3阶行列式
  8. Kafka动态认证SASL/SCRAM配置+整合springboot配置
  9. 2020知道答案C语言,C语言及逆向2020知到答案
  10. java上传图片到阿里云oss云存储中,返回url链接地址