0

I'm trying to send sms from my android 6.0 device (Moto G 3rd. Generation) using this code:

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mycompany.sms_global">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.SEND_SMS"/>
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

...

Activity:

import android.telephony.SmsManager;

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage( "12345678" , null, "hello world" , null, null);

But the App crashes and the debugger shows me this:

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 don't work the permissions?

mrcaste
  • 23
  • 8
  • The stacktrace you've posted, doesn't seem to have anything to do with your app crashing because of sending a text-message. Try to clear you LogCat and re-run the app to see if you get something more meaningful. In the title of the question you also state that the exception `UnknownSchemeException` - show us what you're putting into the SMS. Phonenumber and text. – Darwind Apr 26 '16 at 17:41
  • Ok, you're right, I'll edit my question. – mrcaste Apr 26 '16 at 17:47
  • What version of Android are you building against? What is the `targetSdk` set to? You can find it in your `build.gradle` file under `targetSdkVersion`. – Darwind Apr 26 '16 at 18:07
  • @Darwind the targetSdkVersion is 23, I found the answer, thank you. – mrcaste Apr 26 '16 at 18:21
  • No problem :-) maybe to make it easier for the next one maybe asking the same question as you, you could share your solution here... – Darwind Apr 26 '16 at 18:27
  • Sure, the best you can view the official doc to request permissions to users: [here](http://developer.android.com/intl/es/training/permissions/requesting.html) – mrcaste Apr 26 '16 at 21:10

0 Answers0