开发者

Sending an SMS in Android

开发者 https://www.devze.com 2023-02-02 10:27 出处:网络
Hey, I have been making an Android app which needs to send a text message. Here is the current code I have:

Hey, I have been making an Android app which needs to send a text message. Here is the current code I have:

public class getMessage extends Service {
@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    client Phone = new client();


    String[] msg = Phone.getMsg(user[0],user[1]);
    PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, getMessage.class), 0);
    SmsM开发者_如何学运维anager man = SmsManager.getDefault();
    Log.e("GOT MESSAGE", msg[0]+ " : " +msg[1]);
    man.sendTextMessage(msg[0], null, msg[1], pi, null);
    Log.e("Message", "Sent the message?");
}

Now, for some reason, the text message will not send using this code, and I'm not sure why. I was hoping that someone here could help me out in finding why this message won't send.

No error is raised, nothing appears in the log (except for the log messages that I make myself in the code). Also, the manifest does have the correct tags.

Suggestions?


You should check if you have permission for sending SMS.


Well, now, this is embarrassing. Apparently, the way I was doing it WAS correct. Just the way that I was checking to see if it was sent was apparently incorrect.

When sending through code like this, it does not appear as a sent message on the phone, but will be received by the other person. I just had to test this by running two emulators.

Thanks for the help anyways, guys!


does this link help? It basically goes over a sample activity that sends and listens for SMS messages.

0

精彩评论

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