Search code examples
androidsmsandroid-permissionssmsmanager

Android doesn't send SMS message without user interaction


I'm developing an android application that sends text messages. The shipping code is this

Manifest:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.BIND_CARRIER_SERVICES" />
<uses-permission-sdk-23 android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission-sdk-23 android:name="android.permission.RECEIVE_SMS"/>
<uses-permission-sdk-23 android:name="android.permission.SEND_SMS"/>
<uses-permission-sdk-23 android:name="android.permission.INTERNET" />
<uses-permission-sdk-23 android:name="android.permission.BIND_CARRIER_SERVICES" />
<uses-permission-sdk-23 android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

Code:

     SmsManager smsManager
                    = SmsManager.getDefault();

            smsManager.sendTextMessage( sms.getNumber(), providerNumber,
                                        sms.getContent(), sentPI, deliveredPI);

But when the app works the message remains in default SMS app as not sent. I' ve to enter to default app and touch one by one and it sends.

This is my build.gradle

  apply plugin: 'com.android.application'

  repositories {
    jcenter()
  }

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.3'
    defaultConfig {
        applicationId "xxxxxx.xxxxxxx"
        minSdkVersion 22
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"                            
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.4.0'
testCompile 'junit:junit:4.12'
compile 'com.github.kittinunf.fuel:fuel:1.4.0' //for JVM
compile 'com.github.kittinunf.fuel:fuel-android:1.4.0' //for Android
compile 'com.github.kittinunf.fuel:fuel-rxjava:1.4.0' //for RxJava support
}

How can I solve this?


Solution

  • Finally I found the solution... it was that I thought. Trouble is that I was trying to send SMS from another Thread. It's assumed to send from Main Ui Thread. The code provided by Google works only in Main UI Thread. Currently I'm trying to use a service to see if works!