如何将消息从一个设备发送到活动外的其他设备?

时间:2011-06-15 10:06:44

标签: android messaging

如何实现向其他设备发送邮件的代码?

这样的方法
public void sndSms(String phoneNumber, String message)

注意:我的班级没有extends ActivityonCreate()方法。那我该如何实现sndSms()方法?

2 个答案:

答案 0 :(得分:1)

我找到了这个解决方案,当我以为我也会遇到这个问题时。但对我来说没有必要。

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

答案 1 :(得分:1)

我猜你必须在某个时候开展活动。所以你只需要将它的Context传递给你的方法。

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

在活动中只需使用

xxx.sndSms("number", "message", myActivity.this);
相关问题