Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending an SMS in Android

Tags:

java

android

sms

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);
    SmsManager 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?

like image 616
D4N14L Avatar asked Jan 05 '11 22:01

D4N14L


People also ask

What are two ways to send SMS in Android?

In android, we can send SMS from our android application in two ways either by using SMSManager API or Intents based on our requirements. If we use SMSManager API, it will directly send SMS from our application.

Why can't I send SMS messages on my Android phone?

If your Android won't send text messages, the first thing you should do is make sure you have a decent signal — without cell or Wi-Fi connectivity, those texts are going nowhere. A soft reset of an Android can usually fix an issue with outgoing texts, or you can also force a power cycle reset.

What is the difference between a text message and an SMS?

The first and biggest thing to know about the difference between SMS and text messages is that there is no difference. SMS, or Short Message Service, is a form of text message that's sent from one device to another.


1 Answers

You should check if you have permission for sending SMS.

like image 81
Ante Avatar answered Oct 01 '22 19:10

Ante