-
Notifications
You must be signed in to change notification settings - Fork 380
Open
Description
How can we help?
I want to create a vibration when the OneSignal push notification with the condition of the app is killed which means the app does not run in the foreground or background.
for this, I am using
Android Notification Service Extension from Onesignal docs.
But I having issues with Unresolved Reference with multiple classes and members .
this is native class that i created
package com.statemanagement
import android.content.Context
import android.os.VibrationEffect
import android.os.Vibrator
import com.onesignal.OSNotification
import com.onesignal.OSNotificationReceivedEvent
import com.onesignal.OneSignal.OSRemoteNotificationReceivedHandler
class NotificationServiceExtension : OSRemoteNotificationReceivedHandler {
fun remoteNotificationReceived(
context: Context,
notificationReceivedEvent: OSNotificationReceivedEvent
) {
val notification: OSNotification = notificationReceivedEvent.notification
// Trigger vibration when a notification is received
triggerVibration(context)
notificationReceivedEvent.complete(notification)
}
// Function to trigger vibration
private fun triggerVibration(context: Context) {
val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
if (vibrator.hasVibrator()) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
val vibrationEffect =
VibrationEffect.createOneShot(5000, VibrationEffect.DEFAULT_AMPLITUDE)
vibrator.vibrate(vibrationEffect)
} else {
vibrator.vibrate(longArrayOf(500, 1000, 500), -1)
}
}
}
}
in this com.onesignal refers to react-native-onesignal module, not get the following classes and function.
OSNotification
OSNotificationReceivedEvent
OSRemoteNotificationReceivedHandler
notification
complete
What should I do to slove this Unresolved Reference Error?
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
No labels