2015-04-04 98 views

回答

0

是的,它是可能的,你可以覆盖电源按钮的点击事件是这样的:

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" /> 
+0

感谢u为代码。但是在这一行“dispatchKeyEvent(KeyEvent event)”中得到一个错误,它说这个方法必须返回一个布尔类型的结果。 – nan0133 2015-04-04 16:08:42

+0

我修改了代码 – user1888162 2015-04-04 17:46:56

相关问题