【发布时间】:2015-04-04 13:58:59
【问题描述】:
我是android的新手。我想知道按两次电源按钮是否可以拨打指定号码。
【问题讨论】:
我是android的新手。我想知道按两次电源按钮是否可以拨打指定号码。
【问题讨论】:
是的,有可能,您可以像这样覆盖电源按钮单击事件:
long last_click = 0;
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
// Check if power button was pressed twice in last second
if ((System.currentTimeMillis() - last_click) <= 1000) {
// Make call if pressed twice
call();
return true;
}
last_click = System.currentTimeMillis();
}
return super.dispatchKeyEvent(event);
}
public void call() {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phone));
startActivity(callIntent);
}
在清单中添加调用权限:
<uses-permission android:name="android.permission.CALL_PHONE" />
【讨论】: