lundi 7 avril 2014

Sending SMS with Android


This is a quick example on how to integrate the SMS your app. Threre are two ways to do it:
  • Programmatically
public void SendSms(string phoneNumber, string smsMessage){

         SmsManager mySmsManager = SmsManager.getDefault();

         mySmsManager .sendTextMessage(phoneNumber, null, smsMessage, null, null);

}
  • Using the built in Android SMS Application 

public void builtINSMS(string phoneNumber,string message) {

        Intent intentSMS = new Intent(Intent.ACTION_VIEW);



        intentSMS.putExtra("sms_body", message);

        intentSMS.putExtra("address", phoneNumber);

        intentSMS.setType("vnd.android-dir/mms-sms");

        startActivity(intentSMS );

}


Don't forget to add Sending SMS permission in your manifest file

<uses-permission android:name="android.permission.SEND_SMS" />

Aucun commentaire:

Enregistrer un commentaire