简体   繁体   English

SMS使用SmsManager作为后台服务发送

[英]SMS send as a background Service using SmsManager

I am trying to create an application in Android 2.2 which sends SMS to 6 different contacts the same msg automatically in background as a Service using android.telephony.SmsManager which supports both CDMA and GSM. 我正在尝试在Android 2.2中创建一个应用程序,它使用支持CDMA和GSM的android.telephony.SmsManager在后台作为Service自动发送短信给6个不同的联系人。

I saw many threads which has a code snippet but they are using which are deprecated ie import android.telephony.gsm.SmsManager; 我看到很多线程都有一个代码片段,但是他们使用的是不推荐的,即import android.telephony.gsm.SmsManager; so i just replaced it with import android.telephony.SmsManager and wrote the following code & it works 所以我只是用import android.telephony.SmsManager替换它,并编写了以下代码,它的工作原理

  SmsManager sms = SmsManager.getDefault();
  sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);

now , 现在,

1) can anyone tell me the roadmap to create a service which sends up to 6 SMS in background ? 1)任何人都可以告诉我roadmap to create a serviceroadmap to create a service在后台发送最多6条短信吗?

2) moreover is it good to create another thread inside a service to send SMS to make it run in a separate thread for fast result ? 2)此外,在服务中创建另一个线程以发送SMS以使其在单独的线程中运行以获得快速结果是否良好?

i am pretty much new to Android Services section so i am confused what i need to use Remote Service or Local Service , please do ask if you have any question regarding my post 我几乎是Android服务部门的新手,所以我很困惑我需要使用远程服务或本地服务 ,如果您对我的帖子有任何疑问,请询问

1) You only need to follow the LocalService example depicted here 1)您只需要遵循此处描述的LocalService示例

2) You can use any for of android concurrency as depicted here if you choose to. 2)你可以使用任何对所描绘的Android并发在这里 ,如果你选择。

1) I do not see any reason not to follow the normal way for creating a service. 1)我认为没有理由不遵循创建服务的正常方式。 I mean you can just follow the documentation about Service 我的意思是你可以按照有关服务的文档

2) Yes it is good to start a thread to perform actions in the background in a service 2)是的,开始一个线程在服务的后台执行操作是好的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM