I created a Backgroundservice where i want to send SMS in the Background when i press the power button for example.
This is my code for sending sms when i press the power button:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, "Ich brauche Hilfe! Hier ist mein aktueller Standort, kannst du mir helfen kommen?" + "\n" + "http://maps.google.com/?q=" + lat + "," + lon, null, null);
return true;
}
return super.onKeyDown(keyCode, event);
What i want to ask is: Do i need to write this code into my Backgroundervice and start the Service in the MainActivty onKeyDown? or keep it in my MainActivity?