0

I'm creating an app that needs to send an automatic SMS on the users phone. I've tested with many phones with versions under 7.0 and they all worked. I've also tested on the emulators (7.0) and it worked fine but when I tested with two (real) 7.0 android phones it crashed. Can someone help?

Thanks in advance.

Code that I'm using to send message:

String message1 = "Oi! Eu saí de " + localizacaoFrom + " e fui até " + localizacaoTo + " hoje, mas se você recebeu essa mensagem, significa que talvez algo tenha ocorrido comigo. Você poderia me ligar? (Eu utilizei o app SempreSeguro para enviar esta mensagem)";

    SmsManager smsManager = SmsManager.getDefault();

        ArrayList<String> parts = smsManager.divideMessage(message1);

            smsManager.sendMultipartTextMessage(FirstNumber, null, parts, null, null);

My build.grade (just in case):

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
    applicationId "com.xxx.xxxxxxx"
    minSdkVersion 17
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        debuggable true
    }
}
productFlavors {
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
}
Lucas
  • 41
  • 4
  • "it crashed" -- use LogCat to examine the Java stack trace associated with the crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Jun 01 '17 at 10:42
  • @CommonsWare thanks but the problem is that the phones I'm testing are not with me, so I send the app's APK to my friends and they just test it for me... – Lucas Jun 01 '17 at 20:21
  • Then you should be integrating something that sends you the crash logs. There are many options. Some use [ACRA](http://acra.ch/) as the Java API, others have their own proprietary one. – CommonsWare Jun 01 '17 at 20:30

1 Answers1

0

Starting with Android 6.0 (Api 23) having the permission in manifest is not enough. You will additionally need to ask the user for permission. See https://stackoverflow.com/a/32636039/4529404 and https://stackoverflow.com/a/41957460/4529404

I don't know why it worked in the emulator though. (It shouldn't imo.)

dreua
  • 527
  • 2
  • 15