Cordova App - Android应用程序:名称

时间:2017-07-10 21:15:38

标签: android cordova android-manifest cordova-plugins android-build

我正在尝试使用两个Cordova插件,当然这两个插件都需要应用Android:名称来设置。

插件: https://github.com/CleverTap/clevertap-cordovahttps://github.com/taivo/parse-push-plugin

在其他类似帖子之后,我创建了一个MainApplication文件,并尝试将这两个插件扩展到新的公共类中。我是业余爱好者所以我确定我做错了,因为我在尝试构建时收到以下错误消息。

MainApplication.java:8: error: class CleverTapPlugin is public, should be declared in a file named CleverTapPlugin.java
public class CleverTapPlugin extends Application {

MainApplication.java:12: error: class ParsePushApplication is public, should be declared in a file named ParsePushApplication.java
public class ParsePushApplication extends CleverTapPlugin {

MainApplication.java:4: error: ParsePushApplication is already defined in this compilation unit
import github.taivo.parsepushplugin.ParsePushApplication;

MainApplication.java:5: error: CleverTapPlugin is already defined in this compilation unit
import com.clevertap.cordova.CleverTapPlugin;

这是我的MainActivity文件:

package com.example.app;

import android.app.Application;
import github.taivo.parsepushplugin.ParsePushApplication;
import com.clevertap.cordova.CleverTapPlugin;


public class CleverTapPlugin extends Application {

}

public class ParsePushApplication extends CleverTapPlugin {

}

public class MainApplication extends ParsePushApplication {

}

似乎我的MainActivity在构建中被正确调用,因为我收到这些错误消息,但我确定我做错了什么。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

根据CleverTap Android文档,如果您使用的是自己的Application类,则可以在课程ActivityLifecycleCallback.register(this);之前致电super.onCreate()

此外,如果您想使用自己的活动生命周期监听器,请更新它以包含以下代码:

application.registerActivityLifecycleCallbacks(
        new android.app.Application.ActivityLifecycleCallbacks() {

            @Override
            public void onActivityCreated(Activity activity, Bundle bundle) {
                CleverTapAPI.setAppForeground(true);
                try {
                    CleverTapAPI.getInstance(application).event.pushNotificationEvent(activity.getIntent().getExtras());
                } catch (Throwable t) {
                    // Ignore
                }
                try {
                    Intent intent = activity.getIntent();
                    Uri data = intent.getData();
                    CleverTapAPI.getInstance(application).pushDeepLink(data);
                } catch (Throwable t) {
                    // Ignore
                }
            }

            @Override
            public void onActivityStarted(Activity activity) {
            }

            @Override
            public void onActivityResumed(Activity activity) {
                try {
                    CleverTapAPI.getInstance(application).activityResumed(activity);
                } catch (Throwable t) {
                    // Ignore
                }
            }

            @Override
            public void onActivityPaused(Activity activity) {
                try {
                    CleverTapAPI.getInstance(application).activityPaused(activity);
                } catch (Throwable t) {
                    // Ignore
                }
            }

            @Override
            public void onActivityStopped(Activity activity) {
            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
            }

            @Override
            public void onActivityDestroyed(Activity activity) {
            }
        }
);

有关详细信息,请查看以下链接 -

CleverTap Documentation - Advanced Topics

CleverTap Documentation - Getting Started