pc控制android手机屏幕亮度,调整android手机屏幕亮度
贴一段调整安卓手机屏幕亮度的代码 ,可以参考使用,见下:
public void setBrightness(int level) {
ContentResolver cr = getContentResolver();
Settings.System.putInt(cr, "screen_brightness", level);
try {
defaultLevel = Settings.System.getInt(cr, "screen_brightness");
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
Window window = getWindow();
LayoutParams attributes = window.getAttributes();
float flevel = level;
attributes.screenBrightness = flevel / 255;
getWindow().setAttributes(attributes);
}
此外,UiModeManager这个类提供了控制系统UI模式的服务,可以参考使用:
{
UiModeManager uim = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
int i = uim.getCurrentModeType();
if (i != Configuration.UI_MODE_TYPE_CAR) {
uim.enableCarMode(0);
}
uim.setNightMode(UiModeManager.MODE_NIGHT_YES);
}
关于UiModeManager的代码见下:
package android.app;
import android.content.Context;
import android.content.res.Configuration;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
/**
* This class provides access to the system uimode services. These services
* allow applications to control UI modes of the device.
* It provides functionality to disable the car mode and it gives access to the
* night mode settings.
*
*
These facilities are built on top of the underlying
* {@link android.content.Intent#ACTION_DOCK_EVENT} broadcasts that are sent when the user
* physical places the device into and out of a dock. When that happens,
* the UiModeManager switches the system {@link android.content.res.Configuration}
* to the appropriate UI mode, sends broadcasts about the mode switch, and
* starts the corresponding mode activity if appropriate. See the
* broadcasts {@link #ACTION_ENTER_CAR_MODE} and
* {@link #ACTION_ENTER_DESK_MODE} for more information.
*
*
In addition, the user may manually switch the system to car mode without
* physically being in a dock. While in car mode -- whether by manual action
* from the user or being physically placed in a dock -- a notification is
* displayed allowing the user to exit dock mode. Thus the dock mode
* represented here may be different than the current state of the underlying
* dock event broadcast.
*
*
You do not instantiate this class directly; instead, retrieve it through
* {@link android.content.Context#getSystemService
* Context.getSystemService(Context.UI_MODE_SERVICE)}.
*/
public class UiModeManager {
private static final String TAG = "UiModeManager";
/**
* Broadcast sent when the device's UI has switched to car mode, either
* by being placed in a car dock or explicit action of the user. After
* sending the broadcast, the system will start the intent
* {@link android.content.Intent#ACTION_MAIN} with category
* {@link android.content.Intent#CATEGORY_CAR_DOCK}
* to display the car UI, which typically what an application would
* implement to provide their own interface. However, applications can
* also monitor this Intent in order to be informed of mode changes or
* prevent the normal car UI from being displayed by setting the result
* of the broadcast to {@link Activity#RESULT_CANCELED}.
*/
public static String ACTION_ENTER_CAR_MODE = "android.app.action.ENTER_CAR_MODE";
/**
* Broadcast sent when the device's UI has switch away from car mode back
* to normal mode. Typically used by a car mode app, to dismiss itself
* when the user exits car mode.
*/
public static String ACTION_EXIT_CAR_MODE = "android.app.action.EXIT_CAR_MODE";
/**
* Broadcast sent when the device's UI has switched to desk mode,
* by being placed in a desk dock. After
* sending the broadcast, the system will start the intent
* {@link android.content.Intent#ACTION_MAIN} with category
* {@link android.content.Intent#CATEGORY_DESK_DOCK}
* to display the desk UI, which typically what an application would
* implement to provide their own interface. However, applications can
* also monitor this Intent in order to be informed of mode changes or
* prevent the normal desk UI from being displayed by setting the result
* of the broadcast to {@link Activity#RESULT_CANCELED}.
*/
public static String ACTION_ENTER_DESK_MODE = "android.app.action.ENTER_DESK_MODE";
/**
* Broadcast sent when the device's UI has switched away from desk mode back
* to normal mode. Typically used by a desk mode app, to dismiss itself
* when the user exits desk mode.
*/
public static String ACTION_EXIT_DESK_MODE = "android.app.action.EXIT_DESK_MODE";
/** Constant for {@link #setNightMode(int)} and {@link #getNightMode()}:
* automatically switch night mode on and off based on the time.
*/
public static final int MODE_NIGHT_AUTO = Configuration.UI_MODE_NIGHT_UNDEFINED >> 4;
/** Constant for {@link #setNightMode(int)} and {@link #getNightMode()}:
* never run in night mode.
*/
public static final int MODE_NIGHT_NO = Configuration.UI_MODE_NIGHT_NO >> 4;
/** Constant for {@link #setNightMode(int)} and {@link #getNightMode()}:
* always run in night mode.
*/
public static final int MODE_NIGHT_YES = Configuration.UI_MODE_NIGHT_YES >> 4;
private IUiModeManager mService;
/*package*/ UiModeManager() {
mService = IUiModeManager.Stub.asInterface(
ServiceManager.getService(Context.UI_MODE_SERVICE));
}
/**
* Flag for use with {@link #enableCarMode(int)}: go to the car
* home activity as part of the enable. Enabling this way ensures
* a clean transition between the current activity (in non-car-mode) and
* the car home activity that will serve as home while in car mode. This
* will switch to the car home activity even if we are already in car mode.
*/
public static final int ENABLE_CAR_MODE_GO_CAR_HOME = 0x0001;
/**
* Force device into car mode, like it had been placed in the car dock.
* This will cause the device to switch to the car home UI as part of
* the mode switch.
* @param flags Must be 0.
*/
public void enableCarMode(int flags) {
if (mService != null) {
try {
mService.enableCarMode(flags);
} catch (RemoteException e) {
Log.e(TAG, "disableCarMode: RemoteException", e);
}
}
}
/**
* Flag for use with {@link #disableCarMode(int)}: go to the normal
* home activity as part of the disable. Disabling this way ensures
* a clean transition between the current activity (in car mode) and
* the original home activity (which was typically last running without
* being in car mode).
*/
public static final int DISABLE_CAR_MODE_GO_HOME = 0x0001;
/**
* Turn off special mode if currently in car mode.
* @param flags May be 0 or {@link #DISABLE_CAR_MODE_GO_HOME}.
*/
public void disableCarMode(int flags) {
if (mService != null) {
try {
mService.disableCarMode(flags);
} catch (RemoteException e) {
Log.e(TAG, "disableCarMode: RemoteException", e);
}
}
}
/**
* Return the current running mode type. May be one of
* {@link Configuration#UI_MODE_TYPE_NORMAL Configuration.UI_MODE_TYPE_NORMAL},
* {@link Configuration#UI_MODE_TYPE_DESK Configuration.UI_MODE_TYPE_DESK}, or
* {@link Configuration#UI_MODE_TYPE_CAR Configuration.UI_MODE_TYPE_CAR},
*/
public int getCurrentModeType() {
if (mService != null) {
try {
return mService.getCurrentModeType();
} catch (RemoteException e) {
Log.e(TAG, "getCurrentModeType: RemoteException", e);
}
}
return Configuration.UI_MODE_TYPE_NORMAL;
}
/**
* Sets the night mode. Changes to the night mode are only effective when
* the car or desk mode is enabled on a device.
*
*
The mode can be one of:
*
*
{@link #MODE_NIGHT_NO} - sets the device into notnight
* mode.
*
{@link #MODE_NIGHT_YES} - sets the device into night mode.
*
*
{@link #MODE_NIGHT_AUTO} - automatic night/notnight switching
* depending on the location and certain other sensors.
*
*/
public void setNightMode(int mode) {
if (mService != null) {
try {
mService.setNightMode(mode);
} catch (RemoteException e) {
Log.e(TAG, "setNightMode: RemoteException", e);
}
}
}
/**
* Returns the currently configured night mode.
*
* @return {@link #MODE_NIGHT_NO}, {@link #MODE_NIGHT_YES}, or
* {@link #MODE_NIGHT_AUTO}. When an error occurred -1 is returned.
*/
public int getNightMode() {
if (mService != null) {
try {
return mService.getNightMode();
} catch (RemoteException e) {
Log.e(TAG, "getNightMode: RemoteException", e);
}
}
return -1;
}
}
pc控制android手机屏幕亮度,调整android手机屏幕亮度相关推荐
- android 音量级别调节,调整Android音量等级及默认音量
Android系统定制时,需要调整音量等级,以便实现更精确的音量,可通过如下方式修改.以通话音量等级为例 diff --git a/frameworks/base/services/core/java ...
- Android起始内存大,调整Android Studio分配内存大小
如果Androidstudio运行起来非常卡顿.缓慢,很可能是因为初始分配的内存不够导致卡顿. 查看当前分配的Heap 总大小以及使用状况可以在studio中设置展示.具体位置Settings -&g ...
- nvidia驱动安装,屏幕偏移调整,及屏幕刷新率解决办法(摘自:中国Linux公社)
声明:Linux老鸟谢绝观看!! 1.NVIDIA驱动下载,安装. 下载:http://download.chinaunix.net/download/0008000/7533.shtml 注:如果你 ...
- linux调大屏幕分辨率,调整Linux操作系统屏幕分辨率
在命令行下运行: gtf 1024 768 60 我的笔记本的刷新率是60Hz. [root@localhost ~]# gtf 1024 768 60 # 1024x768 @ 60.00 Hz ( ...
- 要绘图,首先得调整画笔,待画笔调整好之后,再将图像绘制到画布上,这样才可以显示在手机屏幕上。Android 中的画笔是 Paint类,Paint 中包含了很多方法对其属性进行设置,主要方法(没有全部列
要绘图,首先得调整画笔,待画笔调整好之后,再将图像绘制到画布上,这样才可以显示在手机屏幕上.Android 中的画笔是 Paint类,Paint 中包含了很多方法对其属性进行设置,主要方法(没有全部列 ...
- 手机消息同步+android屏幕镜像=电脑微信 for linux
目录 引言 先看看效果图 镜像工具选型 实现步骤 adb安装 消息同步安装 镜像软件安装 控制手机 附:操作快捷键 引言 由于工作原因,需要使用linux,但平日里的工作又离不开windows电脑,所 ...
- android中关于手机屏幕的相关操作(获取屏幕的宽高等操作)
这里总结下android中关于手机屏幕的相关操作: 1.获取屏幕的分辨率(因为android中处理显示的时候,需要根据屏幕分辨率的不同才去不同的布局或显示不同的素材) <uses-sdk and ...
- Android源码编译:任意界面屏幕边缘上滑弹出快捷操作栏【一键加速、开关控制】
<The Fucking Source Code> 注:以下均为android源码Framework层修改. 设计实现在任意界面从屏幕边缘上滑弹出快捷操作栏,包括亮度调节.正在后台运行的程 ...
- DCloud之Android平台应用启动时读写手机存储、访问设备信息(如IMEI)等权限策略控制
目录 一.控制缘由 二.说明 三.云端打包配置 1.读写手机存储权限 (1)源码视图配置 2.访问设备信息权限 (1)源码视图配置 四.离线打包提示语配置及弹窗配置 1.提示语配置 2.弹窗配置 五. ...
最新文章
- R语言使用回归方法解决方差分析问题
- 计算机教研活动心得体会,信息技术研修教研活动总结
- 公司邮箱发邮件的util类
- linux初级命令行
- 一起学JAVA 接口 面向接口开发
- 卸载掉WPS后安装Office文档图标显示异常
- 东方证券万字报告:微信视频号进入稳定的发展期
- 物联网技术及应用计算机,物联网的关键技术及计算机物联网的应用
- python简易双人五子棋
- iOS开发-dispatch_once相关
- python中使用ffmpeg合并音频与视频_FFMpeg无损合并视频的多种方法
- 高通MSM8953点屏记录
- oa系统打不开只能重启服务器,oa系统打不开怎么办-oa系统打不开的解决方法 - 河东软件园...
- 哈工大计算机系统大作业——程序人生-Hello’s P2P
- 边缘计算卸载算法--GT-GAOA
- 怎么生成a类型的对象 java_用一个 java 程序! 写一个类A, 该类创建的对象可以调用方法f输出英文字母表,然后再编写...
- 电脑显示U盘,但是读取不了
- win10开机/睡眠唤醒的时候输入pin,不能输入字母,但是能输入数字,解决办法
- e5408fc4a618ed2a663d0306def2cec3 (学生实验,谢谢)
- 信息技术服务标准(ITSS)
热门文章
- 百元左右平替苹果耳机有哪些?值得入手的蓝牙耳机推荐
- ​让饭圈女孩杀入币圈
- 随机过程总结(4)--泊松过程
- Python搭建UDP网络通信模型,制作一个简单的私人聊天器~
- linux cut -b用法,Linux cut 命令详解
- 文科如何晋级计算机职称,文科学历的人也想评工程师职称怎么办,这些条件满足就行...
- Typora 瘦身 + 标题编号 + 图片同步
- pta上 7-5 统计英文段落的字母频度 (20 分)
- 解决idea注释含空格问题
- 苹果持续回调做多注意节奏,橡胶认购大涨,YP再创新低2022.4.18