我正在尝试将 Swrve 插件集成到我的 Android 项目中。以下是我们在 MainActivity 中得到的代码
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(MyPlugin.class);
}});
try {
SwrveConfig config = new SwrveConfig();
// To use the EU stack, include this in your config.
// config.setSelectedStack(SwrveStack.EU);
SwrveSDK.createInstance(this, <app_id>, "<api_key>", config);
} catch (IllegalArgumentException exp) {
Log.e("SwrveDemo", "Could not initialize the Swrve SDK", exp);
}
}
}
当我运行代码时,出现以下错误
error: incompatible types: MainActivity cannot be converted to Application
网站上的参考代码如下
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
try {
SwrveConfig config = new SwrveConfig();
// To use the EU stack, include this in your config.
// config.setSelectedStack(SwrveStack.EU);
SwrveSDK.createInstance(this, <app_id>, "<api_key>", config);
} catch (IllegalArgumentException exp) {
Log.e("SwrveDemo", "Could not initialize the Swrve SDK", exp);
}
}
}
在离子项目中,我有 MainActivity 而不是
public class MainActivity extends BridgeActivity {
在文档中我有这个
public class YourApplication extends Application {
并在初始化行中,此关键字试图引用 Application 而不是 MainActivity
SwrveSDK.createInstance(this, <app_id>, "<api_key>", config);
我对本机代码一无所知,所以如果有人可以指导我并解释我可以解决的问题,我将不胜感激。