In AndroidManifest.xml 加上权限:
<uses-permission android:name="android.permission.WAKE_LOCK" />
public class UnLockActivity2 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
public class UnLockActivity extends Activity {
/** Called when the activity is first created. */
WakeLock m_wklk;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
m_wklk = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "cn");
m_wklk.acquire(); //设置保持唤醒
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
m_wklk.release(); //解除保持唤醒
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
m_wklk.release();//解除保持唤醒
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
m_wklk.acquire(); //设置保持唤醒
PowerManager
主要是这两个参数:PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE
下面是 android 官方API 解释:
he following flags are defined, with varying effects on system power.These flags are mutually exclusive - you may only specify one of them.
Flag Value CPU Screen Keyboard
PARTIAL_WAKE_LOCK On* Off Off
SCREEN_DIM_WAKE_LOCK On Dim Off
SCREEN_BRIGHT_WAKE_LOCK On Bright Off
FULL_WAKE_LOCK On Bright Bright
一般要使程序运行过程中背景保持常亮,使用
SCREEN_BRIGHT_WAKE_LOCK 就可以,
SCREEN_BRIGHT_WAKE_LOCK CPU:唤醒 屏幕背光:唤醒 键盘灯:关闭
第二个参数:
In addition, you can add two more flags, which affect behavior of the screen only.These flags have no effect when combined with aPARTIAL_WAKE_LOCK.
Flag Value Description
ACQUIRE_CAUSES_WAKEUP Normal wake locks don't actually turn on the illumination. Instead, they cause the illumination to remain on once it turns on (e.g. from user activity). This flag will force the screen and/or keyboard to turn on immediately, when the WakeLock is acquired. A typical use would be for notifications which are important for the user to see immediately.
ON_AFTER_RELEASE If this flag is set, the user activity timer will be reset when the WakeLock is released, causing the illumination to remain on a bit longer. This can be used to reduce flicker if you are cycling between wake lock conditions.
In AndroidManifest.xml 加上权限: 方法一:public class UnLockActivity2 extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super
今天随便尝试了一个
android
的标签,VideoView,实现的代码很简单,但是出现了:
java.lang.SecurityException: Neither user 10001 nor current process has
android
.
permission
.
WAKE
_
LOCK
.
要求添加控制
屏幕
亮度以及睡眠的权限
android
.
permission
.
WAKE
_
LOCK
,
java.lang.SecurityException: Neither user *** nor current process has
android
.
permission
.READ_PHONE
java.lang.SecurityException: Neither user 10253 nor current process has
android
.
permission
.READ_PHONE_STATE.
这个报错异常出现在荣耀6P手机上,当时我还纳闷,为啥别的手机都没问题,就它崩溃呢。后来...
这是一个
Android
权限,用于允许应用程序请求安装其他应用程序的权限。如果您想在您的应用程序中使用这个权限,您需要在您的
Android
Manifest.xml 文件中声明它,并在运行时请求它。您可以使用以下代码请求这个权限:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// For
Android
O and above
if (!getPackageManager().canRequestPackageInstalls()) {
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, REQUEST_INSTALL_PACKAGES);
} else {
// For
Android
N and below
// No need to request
permission
请注意,您需要在
Android
Manifest.xml 文件中添加以下权限声明:
<uses-
permission
android
:name="
android
.
permission
.REQUEST_INSTALL_PACKAGES" />
这样,您的应用程序就可以请求安装其他应用程序的权限了。