首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android 锁屏跟黑屏的广播消息

2012-08-24 
Android 锁屏和黑屏的广播消息一下方法或设置均未验证锁屏或黑屏会广播两个消息分别是:ACTION_S

Android 锁屏和黑屏的广播消息

一下方法或设置均未验证

==========

锁屏或黑屏会广播两个消息分别是:ACTION_SCREEN_OFF和ACTION_SCREEN_ON
程序控制手机永远不锁屏或者永远亮光:通过设置View.setKeepScreenOn(boolean)的方法可以永不锁屏

?

===========以下方法作者声称没有监听到该广播===========

public void onReceive(Context context, Intent intent) {
??
if(intent.getAction().equals( "android.intent.action.SCREEN_OFF" )){
? Toast.makeText(context, "bbbb", Toast.LENGTH_LONG).show();

}
? }
? xml文件中如下:
? <receiver android:name="ServiceReceiver">
<intent-filter>
<action android:name="android.intent.action.SCREEN_OFF" />
</intent-filter>
</receiver>
================以下禁止锁屏方法未验证==============

在每个Activity的onCreate里面加上如下代码就可以了:
@Override
protected void onCreate(Bundle icicle){
? super.onCreate(icicle);
? getWindow();addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

1 楼 vanezkw 2011-12-07   锁屏或黑屏会广播两个消息分别是:ACTION_SCREEN_OFF和ACTION_SCREEN_ON
不知道到现在楼主测试没有,锁屏貌似没有广播。上面两个广播都是屏幕广播:
public static final String ACTION_SCREEN_OFF

Since: API Level 1
Broadcast Action: Sent after the screen turns off.
This is a protected intent that can only be sent by the system.

Constant Value: "android.intent.action.SCREEN_OFF"
public static final String ACTION_SCREEN_ON

Since: API Level 1
Broadcast Action: Sent after the screen turns on.
This is a protected intent that can only be sent by the system.

Constant Value: "android.intent.action.SCREEN_ON" 2 楼 zhouxiaoli521 2011-12-11   vanezkw 写道锁屏或黑屏会广播两个消息分别是:ACTION_SCREEN_OFF和ACTION_SCREEN_ON
不知道到现在楼主测试没有,锁屏貌似没有广播。上面两个广播都是屏幕广播:
public static final String ACTION_SCREEN_OFF

Since: API Level 1
Broadcast Action: Sent after the screen turns off.
This is a protected intent that can only be sent by the system.

Constant Value: "android.intent.action.SCREEN_OFF"
public static final String ACTION_SCREEN_ON

Since: API Level 1
Broadcast Action: Sent after the screen turns on.
This is a protected intent that can only be sent by the system.

Constant Value: "android.intent.action.SCREEN_ON"
这个还真没试过,因为一直没用到。。

热点排行