发送短信后台时电源按钮为pressed [英] Sends SMS in Background when Power Button is pressed

查看:299
本文介绍了发送短信后台时电源按钮为pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法告诉我的应用程序做一些事情,而它的在后台运行?我尝试做的是发送短信时,我preSS的电源按钮。
这是我写的,它的作品,而现在我是在应用程序中:

 公共布尔的onkeydown(INT键code,KeyEvent的事件){
    startService(新意图(这一点,BackgroundService.class));
        如果(event.getKey code()== KeyEvent.KEY code_POWER){
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(PHONENO,NULL,非物质文化遗产brauche Hilfe!海尔北京时间炒面aktueller Standort,kannst杜MIR helfen kommen?+\\ n+http://maps.google.com/?q=+纬度+ ,+ LON,NULL,NULL);
            返回true;
        }
    返回super.onKeyDown(键code,事件);
}


解决方案

当你的应用程序是不可见的不是在后台运行。这是处于休眠状态等待恢复或释放。有,而它在这个状态下,它明确地执行一些操作,你需要设置将从您的应用程序独立运行后台服务。要开始,看看这个谷歌指南: http://developer.android.com/guide /components/services.html

Is there a way to tell my app to do something while it's running in the Background? What i try to do is to send a sms when i press the Power Button. This is what i wrote and it works currently while i'm inside the app:

  public boolean onKeyDown(int keyCode, KeyEvent event) {
    startService(new Intent(this, BackgroundService.class));
        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);
}

解决方案

When your app is not visible it isn't "running in the background." It's in a dormant state waiting to be restored or released. To have it explicitly perform some operation while it is in this state, you need to set up a background service that will run independently from your app. To get started, check out this Google guide: http://developer.android.com/guide/components/services.html

这篇关于发送短信后台时电源按钮为pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆