Primero agregamos el permiso en el AndroidManifest.xml arriba de la etiqueta application
<uses-permission android:name="android.permission.SEND_SMS" />
Mi manifest me quedó así:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hector.simplemassivesms" >
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Para enviar SMS hay dos vias:
Usando SmsManager:
SmsManager mySMS = SmsManager.getDefault();
String destination = "16501234567";
String msg = "Enviando mensaje!";
mySMS.sendTextMessage(destination, null, msg, null, null);
O usando intent
String SENT_SMS_FLAG = "SENT_SMS";
String DELIVER_SMS_FLAG = "DELIVER_SMS";
Intent sentIn = new Intent(SENT_SMS_FLAG);
PendingIntent sentPIn = PendingIntent.getBroadcast(this,0,sentIn,0);
Intent deliverIn = new Intent(SENT_SMS_FLAG);
PendingIntent deliverPIn
= PendingIntent.getBroadcast(this,0,deliverIn,0);
No hay comentarios:
Publicar un comentario