gkont
gkont

Reputation: 199

Android, can not import the right startActivityForResult. (Kotlin, compose, android studio)

I'm working in Android studio. In my app, I want to be able to turn the bluetooth on from the app, when it is off. According to the documentation that can be done like this:

if (bluetoothAdapter?.isEnabled == false) {
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
}

The startActivityFromResult function there, takes two arguments (Intent, Int). It looks like though that there are (at least) two startActivityFromResult functions. The second one is in the package

androidx.core.app.ActivityCompat.startActivityForResult

and it takes different arguments (Activity, Intent, Int, ...). That function's signature is

void startActivityForResult(@NonNull Activity activity, @NonNull Intent intent,
        int requestCode, @Nullable Bundle options)

My problem is that I cannot import the right startActivityForResult. When editing in Android studio it gives me only the option to import from the library androidx.core.app.ActivityCompat.startActivityForResult which contains the wrong startActivityForResult.

Can someone help me with this? How can I force android studio to import the right startActivityForResult function. The one with arguments (intent, int)

PS: I have imported in my code the following, that supposedly contain the right function

import androidx.activity.ComponentActivity
import android.app.Activity

but it didn't help. The android studio ignores them.

Upvotes: 0

Views: 23

Answers (0)

Related Questions