Hello everyone I am building onesignal extension using Fast using onesignal.
Java Code
package com.sarthakdev.pushnotification;
import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.*;
import com.onesignal.OneSignal;
import com.onesignal.OSNotificationOpenedResult;
import com.onesignal.OSNotificationReceivedEvent;
import com.onesignal.OneSignal.OSNotificationWillShowInForegroundHandler;
import com.onesignal.OneSignal.OSNotificationOpenedHandler;
@DesignerComponent(
version = 1,
versionName = "1.0",
description = "OneSignal Push Notification Initialization",
iconName = "icon.png"
)
public class PushNotification extends AndroidNonvisibleComponent {
private Context context;
private static final String LOG_TAG = "PushNotification";
public PushNotification(ComponentContainer container) {
super(container.$form());
this.context = container.$context();
}
@SimpleFunction(description = "Initialize OneSignal with your App ID")
public void Initialize(String oneSignalAppId) {
OneSignal.initWithContext(context);
OneSignal.setAppId(oneSignalAppId);
}
@SimpleFunction(description = "Set External User ID")
public void SetExternalUserId(String externalId) {
OneSignal.setExternalUserId(externalId);
}
@SimpleFunction(description = "Remove External User ID")
public void RemoveExternalUserId() {
OneSignal.removeExternalUserId();
}
@SimpleFunction(description = "Prompt for Push Notification Permission")
public void PromptForPushNotifications() {
OneSignal.promptForPushNotifications();
}
@SimpleFunction(description = "Set Notification Received Handler")
public void SetNotificationReceivedHandler() {
OneSignal.setNotificationWillShowInForegroundHandler(new OSNotificationWillShowInForegroundHandler() {
@Override
public void notificationWillShowInForeground(OSNotificationReceivedEvent notificationReceivedEvent) {
// Handle notification received
NotificationReceived(notificationReceivedEvent.getNotification().getBody());
}
});
}
@SimpleFunction(description = "Set Notification Opened Handler")
public void SetNotificationOpenedHandler() {
OneSignal.setNotificationOpenedHandler(new OSNotificationOpenedHandler() {
@Override
public void notificationOpened(OSNotificationOpenedResult result) {
// Handle notification opened
NotificationOpened(result.getNotification().getBody());
}
});
}
@SimpleEvent(description = "Triggered when a notification is received")
public void NotificationReceived(String message) {
EventDispatcher.dispatchEvent(this, "NotificationReceived", message);
}
@SimpleEvent(description = "Triggered when a notification is opened")
public void NotificationOpened(String message) {
EventDispatcher.dispatchEvent(this, "NotificationOpened", message);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sarthakdev.pushnotification">
<application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- You can use any manifest tag that goes inside the <application> tag -->
<!-- <service android:name="com.example.MyService"> ... </service> -->
</application>
<!-- Other than <application> level tags, you can use <uses-permission> & <queries> tags -->
<!-- <uses-permission android:name="android.permission.INTERNET"/> -->
<!-- <queries> ... </queries> -->
</manifest>
fast yml
# The name of the extension developer
author: Sarthak Gupta
# The minimum Android SDK level your extension supports. Minimum SDK defined in
# AndroidManifest.xml or @DesignerComponent are ignored, you should always define it here.
min_sdk: 21
# If enabled, it will optimizes the extension with ProGuard.
proguard: true
# If enabled, Kotlin Standard Libraries (V1.9.24) will be included with the extension.
# If you want to add specific Kotlin Standard Libraries so disable it.
kotlin: true
# If enabled, you will be able to use Java 8 language features in your extension source code.
desugar_sources: true
# Enable it, if any of your dependencies use Java 8 language features.
desugar_deps: true
# If enabled, the D8 tool will generate desugared (classes.jar) classes.dex
desugar_dex: true
# Default repositories are Maven Central, Google Maven, JCenter and JitPack.
# If the library you want to use is not available in these repositories, add here by specifying their URLs.
# repositories:
# - https://repo.spring.io/plugins-release/
# Extension dependencies [JAR & AAR Should be present into deps directory]
dependencies:
- com.onesignal:OneSignal:4.8.3
- com.google.android.gms:play-services-base:18.1.0
- com.google.android.gms:play-services-ads-identifier:18.0.1
- com.google.android.gms:play-services-location:21.0.1 # Added
- androidx.browser:browser:1.5.0 # Added
# Add optional platform-specific dependencies
- com.huawei.hms:location:6.3.0.300 # Huawei Location Services
- com.huawei.hms:push:6.3.0.300 # Huawei Push
# Repositories
repositories:
- https://developer.huawei.com/repo/ # Huawei Maven
- https://jitpack.io
# Define dependencies those are should be skipped during resolving. [Remote only]
# excludes:
# - androidx.recyclerview:recyclerview:1.0.0
# Extension assets. [Should be present into assets directory]
#assets:
#- my-awesome-asset.anything
# If enabled, the version number of every component will be increased automatically.
auto_version: false
# If enabled, @annotations will be not present in built extension.
deannonate: true
# If enabled, matching classes provided by MIT will not be included in the built extension.
filter_mit_classes: false
# If enabled, R8 will be used instead of ProGuard and D8 dexer.
# NOTE: It's an experimental feature.
# R8: false
Please find the error in the code as I am not able to compile it. Upon compiling I get error in MIT app inventor import failed null