Skip to content

07.Notification and Message

Kilnn edited this page Jul 6, 2023 · 19 revisions

Notification

Use FcMessageFeature.sendNotification to send a message notification to the device.

You can send a variety of different message notifications, such as QQ, WeChat, Facebook, etc. But at first, you should use FcDeviceInfo.isSupportNotification to ensure this type is supported. And ensure that the type is enabled in FcNotificationConfig.

The configuration items in FcNotificationConfig are not one-to-one corresponding to the message types in FcNotificationType. This is because there are three types of notifications for telephony types: incoming calls, answering and hanging up.

Because Android does not support ANCS, so these notification messages need to be captured by yourself. Like monitor phone rings and hangs up, listen to the SMS. Other third-party notifications such as QQ, WeChat messages, etc., consider using NotificationListenerService to capture.

Message

The device may send various messages to the phone, and use FcMessageFeature.observerMessage to listen for these messages.

The message type define in FcMessageType

Find phone

sample project: Refer to FindPhoneManager.kt

When receiving FcMessageType.FINE_PHONE type message indicating that the device is finding for the phone.

Usually, after receiving this message on your phone, you need to make a ring or vibration to respond to the device's finding. And when you start responding, you need to send FcMessageFeature.replayFindPhone.

After the finding starts, both parties can actively stop the finding process. Listen FcMessageType.STOP_FINE_PHONE message to stop phone finding, and send FcMessageFeature.stopFindPhone to stop device finding.

Find device

sample project: Refer to OtherFeaturesFragment.kt

Use FcMessageFeature.findDevice to find device.

Camera control

sample project: Refer to CameraActivity.kt

Use FcMessageFeature.observerMessage to listen the camera message:

  • FcMessageType.CAMERA_WAKE_UP: Launch your camera activity
  • FcMessageType.CAMERA_EXIT: Exit your camera activity
  • FcMessageType.CAMERA_TAKE_PHOTO: Take photo in your camera activity.

Use FcMessageFeature.setCameraStatus to send you camera status to device. Such as setCameraStatus(true) on activity resume, setCameraStatus(false) on activity pause.

Media control

Use FcMessageFeature.observerMessage to listen for the following messages to for media control

  • FcMessageType.MEDIA_PLAY_PAUSE
  • FcMessageType.MEDIA_NEXT
  • FcMessageType.MEDIA_PREVIOUS
  • FcMessageType.MEDIA_VOLUME_UP
  • FcMessageType.MEDIA_VOLUME_DOWN
  • FcMessageType.MEDIA_SILENT_MODE

For example, when you receive FcMessageType.MEDIA_VOLUME_UP message, use AudioManager.adjustVolume to increase the ringer volume.

You can use FcBuiltInFeatures.mediaControl without having to handle the messages yourself. See also Built-in features

Music control

When receiving FcMessageType.MUSIC_STATE and FcMessageType.MUSIC_INFO messages, you should use FcMessageFeature.setMusicState and FcMessageFeature.setMusicInfo to send music state/info to device. Usually, MediaSessionManager is used to obtain the current music info and status of the phone.

You can use FcBuiltInFeatures.musicControl without having to handle the message yourself. See also Built-in features.

This feature relies on NotificationListenerService, you need to use FcConnector.musicControlNotificationListenerService to pass in this instance in your NotificationListenerService.Like this:

class MyNotificationListenerService : NotificationListenerService() {

    override fun onCreate() {
        super.onCreate()
        getFcSDK(this).connector.musicControlNotificationListenerService(null)
    }

    override fun onListenerConnected() {
        super.onListenerConnected()
        getFcSDK(this).connector.musicControlNotificationListenerService(this)
    }

    override fun onListenerDisconnected() {
        super.onListenerDisconnected()
        getFcSDK(this).connector.musicControlNotificationListenerService(null)
    }
}

If you extend the FitCloud SDK util class AbsNotificationListenerService, you don't need to call musicControlNotificationListenerService.

Clone this wiki locally