Why i get an error on intent? I want to call a number when a clicking on a floating button.
ContextCompat.startActivity(intent), here a get the error (intent)
Type mismatch. Required:Context Found:Intent
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
fab.setOnClickListener { view ->
Snackbar.make(view, "Secretariaat wordt gebeld",
Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
makePhoneCall("0123456")
}
val toggle = ActionBarDrawerToggle(
this, drawer_layout, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close
)
drawer_layout.addDrawerListener(toggle)
toggle.syncState()
nav_view.setNavigationItemSelectedListener(this)
}
fun makePhoneCall(number: String) : Boolean {
try {
val intent = Intent(Intent.ACTION_CALL)
intent.setData(Uri.parse("tel:$number"))
ContextCompat.startActivity(intent)
return true
} catch (e: Exception) {
e.printStackTrace()
return false
}
}