英文:
How to add fragment activity to MainActivity.java or MainAcyivity.kt
问题
I am trying to build fingerprint feature in my Flutter apps and I am using local_auth package... the problem is that I always get the following error-
PlatformException(no_fragment_activity, local_auth plugin requires activity to be a FragmentActivity., null)
I try to add FragmentActivity to MainActivity.kt but it doesn't work.. here is the structure of my folder... so should I create MainActivity.java? and where should I place MainActivity.java in my folder?
and here is the content of my MainActivity.kt
package com.project
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
英文:
I am trying to build fingerprint fitur in my flutter apps and I am using local_auth package... the problem is that I always get below error-
PlatformException(no_fragment_activity, local_auth plugin requires activity to be a FragmentActivity., null)
I try to add FragmentActivity to MainActivity.kt but it doesn't work.. here is the structure of my folder... so should I create MainActivity.java? and where should I place MainActivity.java in my folder?
and here is the content of my MainActivity.kt
package com.project
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
答案1
得分: 2
这是如何使用Kotlin实现的:
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
import android.os.Build
import android.view.WindowManager
import android.view.ViewTreeObserver
class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}
英文:
Here is how to do it with Kotlin
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterFragmentActivity;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
import android.os.Build
import android.view.WindowManager
import android.view.ViewTreeObserver
class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论