如何将片段活动添加到MainActivity.java或MainActivity.kt。

huangapple go评论112阅读模式
英文:

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?

如何将片段活动添加到MainActivity.java或MainActivity.kt。

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?

如何将片段活动添加到MainActivity.java或MainActivity.kt。

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);
  }
}

huangapple
  • 本文由 发表于 2020年8月14日 14:00:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63407351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定