'Flutter 'onCreate' overrides nothing
I want to add some kotlin code on my flutter app. I add onCreate function on project_name/android/app/src/main/kotlin/com/example/app/MainActivity.kt.
This is my full MainActivity.kt
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.GeneratedPluginRegistrant
import android.os.Environment
import android.net.Uri
import android.content.Intent
class MainActivity: FlutterActivity() {
private val channel = "externalStorage";
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channel).setMethodCallHandler { call, result ->
when (call.method) {
"getExternalStorageDirectory" ->
result.success(Environment.getExternalStorageDirectory().toString())
"getExternalStoragePublicDirectory" -> {
val type = call.argument<String>("type")
result.success(Environment.getExternalStoragePublicDirectory(type).toString())
}
else -> result.notImplemented()
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (!Settings.canDrawOverlays(getApplicationContext())) {
val myIntent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)
val uri: Uri = Uri.fromParts("package", getPackageName(), null)
myIntent.setData(uri)
startActivityForResult(myIntent, REQUEST_OVERLAY_PERMISSIONS)
return
}
}
}
then I got this error on my build
'onCreate' overrides nothing
Unresolved reference: Settings
Unresolved reference: Settings
Unresolved reference:
REQUEST_OVERLAY_PERMISSIONS
Do I need to import some code?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
