我想知道当用户在android中锁定手机时屏幕关闭。我使用BroadCast接收器这样并注册但是我没有关闭屏幕
public class MyActivity extends Activity{
private static final String ACTION = "android.intent.action.ACTION_SCREEN_OFF";
BroadcastReceiver myReceiver;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
context = this;
final IntentFilter theFilter = new IntentFilter();
theFilter.addAction(ACTION);
context.registerReceiver(myReceiver, theFilter);
System.out.println("inside increate");
myReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
System.out.println("phone locked*****");
}
};
}}
如何找出这个问题?
答案 0 :(得分:2)
步骤1:删除private static final String ACTION
行
步骤2:在Intent.ACTION_SCREEN_OFF
行中使用addAction()
(或者,更好的是,只需将其提供给IntentFilter
构造函数并删除addAction()
行)
第3步:使用android.util.Log
代替System.out.println()