开发者

How to send message from one device to other device outside of an Activity?

How can I implement code for sending messages to another device?

A method like

public void sndSms(String phoneNumber, String message)

Note: My class doesn't have extends Activity and onCreate() method. How can I implement sndSms() method then开发者_如何学运维?


I have found this solution, when I thought I will have that problem as well. But it was not necessary for me.

http://www.dotnetexpertsforum.com/how-to-send-sms-programatically-in-android-t1548.html


I guess you've got to have an activity at some point. So you just need to pass its Context to your method.

public void sndSms(String phoneNumber, String message, Context context){
     Intent smsIntent = new Intent(android.content.Intent.ACTION_SEND);
     (...)
     context.startActivity(smsIntent);
}

In activity simply use

xxx.sndSms("number", "message", myActivity.this);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜