本文介绍了解锁Android手机编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写关于如何编程解锁Android手机的code。
我要锁定或解锁手机,当用户点击接近传感器。
公共类MyActivity延伸活动{
私有静态最后弦乐ACTION =android.intent.action.ACTION_SCREEN_OFF;
BroadcastReceiver的myReceiver;
上下文语境;
@覆盖
保护无效的onCreate(包savedInstanceState){
// TODO自动生成方法存根
super.onCreate(savedInstanceState);
上下文=这一点;
最后的IntentFilter theFilter =新的IntentFilter();
theFilter.addAction(ACTION);
context.registerReceiver(myReceiver,theFilter);
的System.out.println(里increate);
myReceiver =新的BroadcastReceiver(){
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
// TODO自动生成方法存根
的System.out.println(手机锁定*****);
}
};
}}
解决方案
@覆盖
保护无效onResume(){
// TODO自动生成方法存根
super.onResume();
IntentFilter的过滤器=新的IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(mIntentReceiver,过滤器);
的System.out.println(广播接收器注册****);
}
私人的BroadcastReceiver mIntentReceiver =新的BroadcastReceiver(){
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
// TODO自动生成方法存根
的System.out.println(手机锁);
}
I want to write the code on how to unlock the Android Phone programmatically.
I want lock or unlock the phone when the user taps the proximity sensor.
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*****");
}
};
}}
解决方案
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(mIntentReceiver, filter);
System.out.println("BROADcast receiver registered****");
}
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
System.out.println("phone locked");
}
这篇关于解锁Android手机编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!