How to implement One Signal Notification in Android App.

===========================================================

1st, we have to implement plugins in build.gradle(Project Level).

id 'com.google.gms.google-services' version '4.4.0' apply false

2nd, we have to implement plugins in build.gradle(Module :app).

 id 'com.google.gms.google-services'

3rd, we have to implement dependency in build.gradle(Module :app).

 implementation platform('com.google.firebase:firebase-bom:32.7.0')
 implementation 'com.google.firebase:firebase-analytics'
 implementation 'com.onesignal:OneSignal:[5.0.0, 5.99.99]'

4th, we have to implement backend code in the JAVA class.

private static final String ONESIGNAL_APP_ID = "App ID Paste Here";
OneSignal.getDebug().setLogLevel(LogLevel.VERBOSE);
OneSignal.initWithContext(this, ONESIGNAL_APP_ID);
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            OneSignal.getNotifications().requestPermission(true, Continue.with(r -> {
                if (r.isSuccess()) {
                    if (Boolean.TRUE.equals(r.getData())) {
                        // `requestPermission` completed successfully and the user has accepted permission
                    } else {
                        // `requestPermission` completed successfully but the user has rejected permission
                    }
                }
            }));
        }

THANK YOU

Scroll to Top