是否可以从我的原生 Android 代码中获取当前活动(如 FooView.java 的构造函数所示,我需要提供一个活动)?
我需要 FooView.java 本身来检查相机权限并检查是否安装了 ARCore。我对 Flutter 和它的平台集成相当陌生,我无法在网上找到答案。如果它是 Flutter 插件,则可以通过该活动访问该活动registrar.activity()
,但我没有注册商,因为我采用了非插件方法(我相信它被称为App 注册)。
MainActivity.java
public class MainActivity extends FlutterActivity {
@Override public void configureFlutterEngine(FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
flutterEngine.getPlatformViewsController().getRegistry().registerViewFactory("fooView", new FooViewFactory());
}
}
FooView.java
public class FooView implements PlatformView {
private boolean requestInstall = true;
FooView(Context context, int id, Map<String, Object> creationParams) {
Activity someActivity = ?????; // TODO: Find where to get the activity holding the view
switch (ArCoreApk.getInstance().requestInstall(someActivity, requestInstall)) {
...
}
}
}