Hello, I am trying to send text messages from my app and using a physical device with Android 6.0 (Moto G 3rd generation), this is the code I use:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("12345678" , null,"hello world" , null, null);
But when executing it, it throws this exception:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.globalsiag.sms_global, PID: 22364
java.lang.SecurityException: Sending SMS message: uid 10113 does not have android.permission.SEND_SMS.
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber(ISms.java:813)
at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:310)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:293)
at com.globalsiag.sms_global.MyGcmListenerService.onMessageReceived(MyGcmListenerService.java:88)
at com.google.android.gms.gcm.GcmListenerService.zzq(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zzp(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zzo(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zza(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Why do not the permissions work? Should I request them for being Android 6.0?