Reputation: 600
I've been using Java for the longest but I recently switched to Kotlin. Here's my problem: I want to start a dialer intent from my app but the compiler returns this error
Type mismatch: inferred type is Intent but Context was expected
This is what I tried:
val num = "tel:54646"
startActivity(Intent(Intent.ACTION_DIAL, Uri.parse(num)))
in java this works:
String num = "tel:54646";
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(num)));
What am I missing here?
Upvotes: 4
Views: 2470
Reputation: 75798
Type mismatch: inferred type is Intent but Context was expected
You should add activity!!
before startActivity
try {
val intent = Intent(Intent.ACTION_DIAL, Uri.parse(num))
activity!!.startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
}
Upvotes: 1