2

I'm trying to implement OneSignal's Push Notification SDK on android and in order to do so, I need to Extend Application Class and call OneSignal.startInit in the onCreate method.

I've been following the guides posted in the documentation and the Android Extend Sample App. Neither of these are working at all.

Trying to build the Android Extend Sample App results in Java ID 0 not found error.

I'm also exploring the possibility of export class AppComponent extends android.app.Application which I'm having no luck with so far.

Any tips would greatly be appreciated!

1 Answer 1

4

There are two ways to achieve this the later being the complicated one

Place the following in your main.ts

var application = require("application");
application.on(application.launchEvent, function (args) {
    if (args.android) {
        // For Android applications
    com.onesignal.OneSignal.startInit(application.android.context).init();
    } else if (args.ios !== undefined) {
        // For iOS applications, args.ios
    }
});

Create a new JavaScript file in your app folder - name it application.android.js

var application = require("application");
var superProto = android.app.Application.prototype;
var Application = android.app.Application.extend("org.myApp.Application", {
    onCreate: function () {
        superProto.onCreate.call(this);
        application.android.init(this);
        com.onesignal.OneSignal.startInit(this).init();
    }
});

Modify the application entry within the AndroidManifest.xml file found in the <application-name>app/App_Resources/Android/ folder

<application
        android:name="org.myApp.Application"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
Sign up to request clarification or add additional context in comments.

1 Comment

The first option worked best for my application. Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.