Description:
I would like to be able to set the app id using the OneSignal.Builder and not the have to use the manifest to declare the OneSignal app id.
You might ask why?
Because there are situation when the OneSignal App id depends on a lot of things and would be nice to be able to download it from our backend instead of hard coding it into the application.
What I was thinking if the builder has an app id set, then the init method could ignore the one in the manifest. Otherwise it would proceed as normal so it wouldn't introduce any breaking change.
If the community would accept such a change, I could try to implement it and submit a PR.
Environment
Using latest SDK 3.9.0
Steps to Reproduce Issue:
There is no way to set the app id programmatically using the OneSignal.Builder
Anything else:
(crash stacktraces, as well as any other information here)
This seems to work for me. I borrowed it from the cordova library android source
OneSignal.init(this.cordova.getActivity(), "<google id>", "<onesignal app id>");
OneSignal.getCurrentOrNewInitBuilder()
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.None)
.unsubscribeWhenNotificationsAreDisabled(true)
.setNotificationReceivedHandler(new OneSignal.NotificationReceivedHandler() {
@Override
public void notificationReceived(OSNotification notification) {
}
})
.init();
Yes. I came up with a similar workaround. But both ways the library will be initialized twice. Also I think in the code you posted the order of the inits are wrong. At least in the android SDK source code the init with the builder parameter always tries to read the app id from the manifest, so first you need to call the builder's init to be able to setup your preferences and then call the init with the app id param.
I'll try switching them around and see what happens. At the moment, it seems to work ok.
The only method to set the OneSignal app_id at runtime is with OneSignal.init().
public static void init(Context context, String googleProjectNumber, String oneSignalAppId, NotificationOpenedHandler notificationOpenedHandler, NotificationReceivedHandler notificationReceivedHandler);
We will consider adding something to the normal builder pattern as well.
Note, googleProjectNumber is ignored as it comes from the value you entered on the OneSignal dashboard for your app.
Hi Guys!
Please help me... I'm using OneSignal with Cordova and I have a special use case. My quesion is how can I call the Init method twice or more times in order to registrate a user for different accounts (in runtime of course). In my case first init works fine in the DeviceReady, but if call another init from JS with a different onesignal project id it doesn't work. How can I achieve this? I think I must modifiy the Java code as well... Thanks for your help.
I added the ap-id in builder and also passed it in the manifest and it registered multiple times so i also request to ignore the one in manifest.
Closing issue. Note: request still under consideration
Most helpful comment
The only method to set the OneSignal app_id at runtime is with
OneSignal.init().We will consider adding something to the normal builder pattern as well.
Note,
googleProjectNumberis ignored as it comes from the value you entered on the OneSignal dashboard for your app.