when compiling the extension in Niotron IDE, I encountered errors. I didn’t understand why the errors appeared
javac] Note: Wrote file file:/compiler/androidX/build/hKDyb/classes/simple_components.json
[javac] Note: Wrote file file:/compiler/androidX/build/hKDyb/classes/simple_components.txt
[javac] Note: Wrote file file:/compiler/androidX/build/hKDyb/classes/simple_components_build_info.json
[javac] Note: Wrote file file:/compiler/androidX/build/hKDyb/classes/AutogeneratedOdeMessages.java
[javac] Note: Wrote file file:/compiler/androidX/build/hKDyb/classes/ComponentsTranslation.java
[javac] /compiler/androidX/src/hKDyb/Dev/amarjeet/sir/OneSignal.java:17: error: package com.onesignal does not existjavac] import com.onesignal.NotificationReceivedHandler;
[javac] ^
[javac] /compiler/androidX/src/hKDyb/Dev/amarjeet/sir/OneSignal.java:18: error: package com.onesignal does not exist
[javac] import com.onesignal.OSNotification;
[javac] ^
[javac] /compiler/androidX/src/hKDyb/Dev/amarjeet/sir/OneSignal.java:19: error: package com.onesignal does not exist
[javac] import com.onesignal.PostNotificationResponseHandler;
[javac] ^
[javac] /compiler/androidX/src/hKDyb/Dev/amarjeet/sir/OneSignal.java:67: error: cannot find symbol
[javac] private class OneSignalNotificationHandler implementsNotificationReceivedHandler {
[javac] ^
[javac] symbol: class NotificationReceivedHandler
[javac] location: class OneSignal
[javac] /compiler/androidX/src/hKDyb/Dev/amarjeet/sir/OneSignal.java:69: error: cannot find symbol
[javac] public void notificationReceived(OSNotification notification) {
[javac] ^
[javac] symbol: class OSNotification
[javac] location: class OneSignal.OneSignalNotificationHandler
[javac] /compiler/androidX/src/hKDyb/Dev/amarjeet/sir/OneSignal.java:74: error: cannot find symbol
[javac] private class OneSignalPostNotificationHandler implements PostNotificationResponseHandler {
[javac] ^javac] ^
[javac] symbol: class PostNotificationResponseHandler
[javac] location: class OneSignal
[javac] 6 errors
package Dev.amarjeet.sir;
import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.*;
import com.onesignal.NotificationReceivedHandler;
import com.onesignal.OSNotification;
import com.onesignal.PostNotificationResponseHandler;
import org.json.JSONException;
import org.json.JSONObject;
@DesignerComponent(
version = 1,
description = "OneSignal Push Notification Extension",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "https://example.com/icon.png")
@SimpleObject(external = true)
public class OneSignal extends AndroidNonvisibleComponent implements Component {
private static final String LOG_TAG = "OneSignalExtension";
private Context context;
private String appId;
public OneSignal(ComponentContainer container) {
super(container.$form());
this.context = container.$context();
this.appId = "";
}
@SimpleProperty(description = "The OneSignal app ID.")
public void AppId(String appId) {
this.appId = appId;
}
@SimpleFunction(description = "Initializes OneSignal with the specified app ID.")
public void Initialize() {
OneSignal.init(context, appId, new OneSignalNotificationHandler());
}
@SimpleFunction(description = "Sends a push notification to the specified user.")
public void SendNotification(String message, String userId) {
JSONObject data = new JSONObject();
try {
data.put("message", message);
data.put("userId", userId);
OneSignal.postNotification(data, new OneSignalPostNotificationHandler());
} catch (JSONException e) {
Log.e(LOG_TAG, "Error creating JSON object for push notification", e);
}
}
private class OneSignalNotificationHandler implements NotificationReceivedHandler {
@Override
public void notificationReceived(OSNotification notification) {
Log.i(LOG_TAG, "Received OneSignal notification: " + notification.payload.body);
}
}
private class OneSignalPostNotificationHandler implements PostNotificationResponseHandler {
@Override
public void onSuccess(JSONObject response) {
Log.i(LOG_TAG, "OneSignal push notification sent successfully.");
}
@Override
public void onFailure(JSONObject response) {
Log.e(LOG_TAG, "Error sending OneSignal push notification: " + response.toString());
}
}
}