Notifications

The AppStudio AppFramework provides a Notifications plug-in that contains tools to alert and inform your app's users at the operating system level outside of the confines of your app.

For an example of this functionality, see the sample app available in ArcGIS AppStudio or in the AppStudio samples GitHub repository.

Local notifications

The LocalNotification component provides the ability to implement notifications to your end users. Not to be confused with push notifications, which come from an external cloud service, local notifications come from the app and are triggered internally. To use the LocalNotification component, you first need to include the following import statement:

 
1
import ArcGIS.AppFramework.Notifications.Local 1.0

A local notification requires the following three parameters to be scheduled:

  • The title of the message
  • The content of the message
  • The time delay after which the notification will display, measured in milliseconds.

These parameters are handled by the schedule method, which sets the notification to trigger after the given number of milliseconds and provides an ID for the notification that can then be used by the clear method to remove it.

Once a notification has been scheduled, the app doesn't need to be in focus or even running for the notification to display. The following code sample is based on the Quick Report template and uses LocalNotification, setting a notification to appear one hour after a report has been sent, to remind the user to send a follow-up report:

                        
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
LocalNotification {
    id: notification
    onTriggered: {
        console.log("Triggered ID: ", id)
    }
}

Component {
    id: addDetailsPage
    AddDetailsPage {
        onNext: {
            if(message=="submit"){
                submitReport()
                notification.schedule("Submit Follow-Up Report", "An hour has passed since your initial report. Please send a follow-up report.", 3600000)
            } else{
                stackView.showResultsPage()
                saveReport()
            }
        }
        onPrevious: {
            stackView.pop();
        }
    }
}

Vibration

In addition to local notifications that provide a visible form of notification, you can also implement nonvisual feedback using the Vibration component. Vibration is commonly used to highlight actions or notify the user, but the most common use is in conjunction with a notification to alert the user to look at their device. To use the Vibration component, include the following import statement:

 
1
import ArcGIS.AppFramework.Notifications 1.0

Vibration is a singleton component, meaning that you can't instantiate it. The following code sample will accompany all local notifications scheduled by the app with a vibration. If the device does not support vibration, a message will instead appear in the console log.

            
1
2
3
4
5
6
7
8
9
10
11
12
LocalNotification {
    id: notification
    onTriggered: {
        console.log("Triggered ID: ", id)
        if(Vibration.supported) {
            Vibration.vibrate()
        }
        else{
            console.log("Vibration not supported on this device.")
        }
    }
}

Currently, there is no way to provide a duration for the Vibration component. On Android devices, the vibration lasts for one second; on other devices, it uses the system default.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.