android - App crash when I try send SMS -


i try send sms in kotlin, wrote simple app following code:

import android.support.v7.app.appcompatactivity import android.os.bundle import android.telephony.smsmanager import android.widget.textview import kotlinx.android.synthetic.main.activity_main.*  class mainactivity : appcompatactivity() {  override fun oncreate(savedinstancestate: bundle?) {     super.oncreate(savedinstancestate)     setcontentview(r.layout.activity_main)     val textview = findviewbyid(r.id.maintextview) textview     send.setonclicklistener {         textview.settext("click")         val sm = smsmanager.getdefault()         sm.sendtextmessage("123123123", null, "test", null, null)         textview.settext("ok")      }   } } 

when try run app via usb cable androidstudio app don't want permissions despite fact i've added permission send_sms manifest. when push button app closes

you have request permission yourself. described in guide

// here, thisactivity current activity if (contextcompat.checkselfpermission(thisactivity,             manifest.permission.send_sms)     != packagemanager.permission_granted) {      // should show explanation?     if (activitycompat.shouldshowrequestpermissionrationale(thisactivity,         manifest.permission.send_sms)) {          // show explanation user *asynchronously* -- don't block         // thread waiting user's response! after user         // sees explanation, try again request permission.      } else {          // no explanation needed, can request permission.          activitycompat.requestpermissions(thisactivity,             new string[]{manifest.permission.send_sms},             my_permissions_request_send_sms);          // my_permissions_request_send_sms         // app-defined int constant. callback method gets         // result of request.     } } 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -