我写了一个应用程序,用户可以在活动中按下按钮发送消息,对我来说这很好用,但现在我的目标是通过双击电源按钮发送短信。
但是我不知道怎么做?
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();
}
}
}
});