由于插件没有自动连接到活动
我已经在现有的Android应用程序中添加了颤动,并且我一直在面对摄影器库不起作用的问题,显示以下错误。
Unhandled Exception: MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker_android)
根据错误,我了解这是由于未注册生成的PluginRegistrant造成的,我必须覆盖configureflutterengine
方法。由于我需要打开片段内的颤动模块,因此我无法使用flutterActivity
扩展活动,因为它不支持getsupportFragmentManager
。 我尝试使用FlutterFragmentActivity
延长活动,并能够覆盖configureflutterengine
方法,但随后遇到了以下错误。
ava.lang.IllegalArgumentException: No view found for id 0x245a3c5c (unknown) for fragment FlutterFragment{647abea (0b17a247-4e8e-42bc-b5f3-6ab0796e458b) id=0x245a3c5c flutter_fragment}
以下是我的mainActivity.java和activity_main.xml
mainActivity.java
package com.mch.testplugin;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.android.FlutterFragment;
import io.flutter.embedding.android.FlutterFragmentActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends AppCompatActivity {
Context mContext;
FlutterFragment flutterFragment;
private static final String TAG_FLUTTER_FRAGMENT = "flutter_fragment";
FlutterEngine mFlutterEngine;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.activity_main);
Button myButton = findViewById(R.id.myButton);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
flutterFragment = (FlutterFragment) getSupportFragmentManager()
.findFragmentByTag(TAG_FLUTTER_FRAGMENT);
// Create and attach a FlutterFragment if one does not exist.
if (flutterFragment == null) {
flutterFragment = FlutterFragment.createDefault();
flutterFragment = FlutterFragment.withNewEngine()
.initialRoute("/")
.build();
getSupportFragmentManager()
.beginTransaction()
.add(
R.id.frame_layout,
flutterFragment,
TAG_FLUTTER_FRAGMENT
)
.commit();
}
});
}
// @Override
// public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
//// super.configureFlutterEngine(flutterEngine);
// mFlutterEngine = flutterEngine;
// GeneratedPluginRegistrant.registerWith(new FlutterEngine(this));
// }
}
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="200dp" />
</androidx.constraintlayout.widget.ConstraintLayout>'
有人可以指导我正确的方法吗?感谢您的帮助。
I have added flutter in an existing Android app and I have been facing issues with Image picker library not working, showing the following error.
Unhandled Exception: MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker_android)
According to the error I understand that it's due to GeneratedPluginRegistrant not being registered and I have to override configureFlutterEngine
method. As I need to open the flutter module inside a fragment I cannot extend my activity using FlutterActivity
because it does not support getSupportFragmentManager
.
I tried extending my activity using FlutterFragmentActivity
and was able to override configureFlutterEngine
method but then faced the following error.
ava.lang.IllegalArgumentException: No view found for id 0x245a3c5c (unknown) for fragment FlutterFragment{647abea (0b17a247-4e8e-42bc-b5f3-6ab0796e458b) id=0x245a3c5c flutter_fragment}
Following are my MainActivity.java and activity_main.xml
MainActivity.java
package com.mch.testplugin;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.android.FlutterFragment;
import io.flutter.embedding.android.FlutterFragmentActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends AppCompatActivity {
Context mContext;
FlutterFragment flutterFragment;
private static final String TAG_FLUTTER_FRAGMENT = "flutter_fragment";
FlutterEngine mFlutterEngine;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.activity_main);
Button myButton = findViewById(R.id.myButton);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
flutterFragment = (FlutterFragment) getSupportFragmentManager()
.findFragmentByTag(TAG_FLUTTER_FRAGMENT);
// Create and attach a FlutterFragment if one does not exist.
if (flutterFragment == null) {
flutterFragment = FlutterFragment.createDefault();
flutterFragment = FlutterFragment.withNewEngine()
.initialRoute("/")
.build();
getSupportFragmentManager()
.beginTransaction()
.add(
R.id.frame_layout,
flutterFragment,
TAG_FLUTTER_FRAGMENT
)
.commit();
}
});
}
// @Override
// public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
//// super.configureFlutterEngine(flutterEngine);
// mFlutterEngine = flutterEngine;
// GeneratedPluginRegistrant.registerWith(new FlutterEngine(this));
// }
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="200dp" />
</androidx.constraintlayout.widget.ConstraintLayout>'
Can someone please guide me the right way to do this? Your help is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
针对类似问题的通常解决方案就是停止应用程序并再次按下运行按钮
The usual solution for similar problems is simply to stop the app and press the run button again