我编写了一个应用程序,用户可以在按下活动中给定的按钮时发送消息,它对我来说很好,但现在我的目标是通过双击电源按钮来发送短信。
但我不知道,该怎么做?
Send SMS by using double press on power button
下面是我用来发送短信的代码:
btnPanic.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String message = "My current location is:" + "\t" + currentLocation ;
String phoneNo = editContacts.getText().toString();
StringTokenizer st=new StringTokenizer(phoneNo,",");
while (st.hasMoreElements())
{
String tempMobileNumber = (String)st.nextElement();
if(tempMobileNumber.length()>0 && message.trim().length()>0) {
sendSMS(tempMobileNumber, message);
}
else
{
Toast.makeText(getBaseContext(),
"Please enter both phone number and message.",
Toast.LENGTH_SHORT).show();
}
}
}
});