开发者

simple app which sends one sms without gui required

I want to write an app to send an sms from a shortcut on a home screen. That is all.

I just can't understand within the framework how I can write such an app. Here's what I've tried so far and what my ideas are:

  1. I wrote an activity that sends an sms using SmsManager within the onCreate() however, this just keeps on sending messages even though the code is not in a loop. I realise I must be not be using an activity the way it's designed to be used. The android application fundamentals article says an activity is for displaying a screen or gui, but I don't need a gui. I just don't know what component I need to to use.

A ser开发者_如何学运维vice? no, because I don't need something running forever in the background. An activity? I guess no because I don't need a gui.

I had an idea to create a broadcast receiver which would respond to a broadcast, so my sens smsm code would be in there ready to send when it receives the signal. But how do i send the signal from an app shortcut on the home screen? What would be the entry point of the app.

I'm just really confused, I've read the tutorials and the app fundamentals and searched forums and not found the answer. There's is just a big gap in my knowledge of the android framework that needs filling I guess, once it clicks I'll be fine but I'm just stuck right now.

Thanks people.


Service does not have to run forever. You can control how long it works in the background, you can even create Service that will shoot once and disappear. Suggestion:

  • from your shortcut (app icon) start Activity. That will be activity with translucent background. To achieve that skip line setContentView() and define theme

@android:style/Theme.Translucent

in your AndroidManifest.xml. This way you will avoid black screen flash at Activity startup.

  • from that Activity start Service and call finish() on that Activity
  • perform SMS sending (you already know how) from Service. Maybe, you do not even need Service, you can send SMS from the translucent Activity.
  • call stopSelf() from your Service immediatelly or after some short timeout (wait for SMS sending result).

All described can be done smoothly through Widget framework. In that case you can even have custom button user may press on. So, that would be another approach.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜