Trying to turn bluetooth on, I used startActivityForResult with arguments (Intent, Int), as follows.
val REQUEST_ENABLE_BT : Int = 1;
if (bluetoothAdapter?.isEnabled == false) {
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
}
I get a type mismatch error for both arguments. "Required Activity - found Intent" for the first argument, "Required Intent - found Int" for the second argument. According to documentation the arguments should be (Intent, Int) as used in the code. I have imported the only suggestion in android studio
import androidx.core.app.ActivityCompat.startActivityForResult
Programming with kotlin, compose. Can somebody help me here?
EDIT: Looks like there are (at least) two different startActivityForResult functions. Android studio (in my project) proposes only the ActivityCompat case for import. I cannot figure out how to import the right one. According to the answers so far, the startActivityForResult that is working with that code is in one of the packages
import androidx.activity.ComponentActivity
import android.app.Activity
But android studio ignores them.
I guess the problem is on your import.
The
startActivityForResultyou are using is thisAnd you should be using this one from
import android.app.Activity