react Native中的本机模块,无法在java类中调用“this”
救救meeee。。。。! 在我的react native项目中,创建了一个本机模块“BeaconModule”,以使用react native不支持的某些功能。在android项目中,它运行良好。但当我将函数AIBeaconManager.init复制到reactnative项目时,它在下面得到了一些错误 这是我的密码react Native中的本机模块,无法在java类中调用“this”,java,android,react-native,Java,Android,React Native,救救meeee。。。。! 在我的react native项目中,创建了一个本机模块“BeaconModule”,以使用react native不支持的某些功能。在android项目中,它运行良好。但当我将函数AIBeaconManager.init复制到reactnative项目时,它在下面得到了一些错误 这是我的密码 我认为这是因为“Context”和“ReactApplicationContext”之间的区别在this之前有一个额外的空括号。在this之前有一个额外的空括号。 public
我认为这是因为“Context”和“ReactApplicationContext”之间的区别在this之前有一个额外的空括号。在this之前有一个额外的空括号。
public class BeaconModule extends ReactContextBaseJavaModule implements AIBeaconListener{
private static ReactApplicationContext reactContext;
BeaconModule(ReactApplicationContext context) {
super(context);
reactContext = context;
Map<String, Object> options = new HashMap<String, Object>() {{
put(AIBeaconManagerInitOption.Keys.AutoServiceRegistrationEnabled, Boolean.valueOf(true));
put(AIBeaconManagerInitOption.Keys.PushNotificationEnabled, Boolean.valueOf(true));
}};
AIBeaconManager aiBeaconManager = AIBeaconManager.init(this, "1062", "09CYvck2rZVNlpQI", options);
}
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/Users/admin/Documents/Working/GPass/GPass/android/app/src/main/java/com/gpass/BeaconModule.java:57: error: incompatible types: BeaconModule cannot be converted to Context
AIBeaconManager aiBeaconManager = AIBeaconManager.init(this, "1062", "09CYvck2rZVNlpQI", options);
^
Note: /Users/admin/Documents/Working/GPass/GPass/android/app/src/debug/java/com/gpass/ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org