Skip to content

Intent (data sharing)

Jacques Bonet edited this page Dec 23, 2019 · 13 revisions

Introduction

React-native provide mechanism that permits to share a document into the desired application.

The application could be in two states:

  • close
  • in background

In Android, we can achieve this with the help of Intent Filters. Intent filters are basically filters that define what an app can expect as its input.

Intent filter are specified in androidmanifest.xml file.

Here an extract for ent:

         <activity
                android:name=".MainActivity"
                android:label="@string/app_name"
                android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
                android:windowSoftInputMode="adjustResize"
                android:launchMode="singleTask"
                android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="application/*"/>
                <data android:mimeType="audio/*"/>
                <data android:mimeType="image/*"/>
                <data android:mimeType="text/*"/>
                <data android:mimeType="video/*"/>
            </intent-filter>
        </activity>
```javascript

In the ent application, we have two intent filters:

One creating an icon on the mobile desktop, permitting to lauch the application
## Set up Google Cloud Messaging (Not Mobile Framework)

> ToDo : Nabil, là je suis largué...

## Configure ODE platform (Not Mobile Framework)

Once Google Cloud Messaging, you will have a private key to put in your ODE Springboard configuration, in `entcore.json`, in the timeline app configuration :

```json
pushNotif = {
    "uri": "https://accounts.google.com:443",
    "tokenUrn": "/o/oauth2/token",
    "scope": "https://www.googleapis.com/auth/firebase.messaging",
    "url": "https://fcm.googleapis.com/v1/projects/{{project_id}}/messages:send",
    "client_mail": {{client_mail}},
    "aud": "https://accounts.google.com/o/oauth2/token",
    "key": {{private_key}}
}

Configure the ENT application to send push-notifications.

A Timeline event that will raise a push-notification has to be configured in his source code, in /src/main/resources/view-src/notify/<application>/<event>.json:

{
    "default-frequency": "DAILY",
    "push-notif": true // Activate push-notifs for this event
}

For more details about all this procedure, check https://github.com/opendigitaleducation/reference-manual/blob/notification/dev/back/notification.adoc.

Set up Push-notification routing for Mobile Framework

If a push-notification is open, all information will be sent to the function in /pushNotifications.ts file.

To add you own routing function, you must create a notifHandler.ts file at the root of your application module's directory, and call it in /pushNotifications.ts :

// other imports
import timelineHandle from "./timeline/notifHandler";
// and your own :
import dummyHandle from "./dummy/notifHandler";

export default dispatch => (data, apps) => {
  // ... other notif handlers
  timelineHandle(dispatch)(data, apps);
  // and you own :
  dummyHandle(dispatch)(data, apps);
};

Your own notifHandler is a thunk action (See "Redux" section of this documentation) and must before all else test if the push-notifiction is applicable to it or not. If it is, then you may use Mobile Framwork routing functions to take the user to the right page :

import Conf from "../Conf";
// Use routing function from here
import { nainNavNavigate } from "../navigation/helpers/navHelper";

export default dispatch => async notificationData => {
  // Test with the resource uri to skip push-notif if not applicable to the application module
  if (!notificationData.resourceUri.startsWith("/dummy")) {
    return;
  }

  // Then, write your notif handler as a regular thunk action.

  // ... get information in notificationData and dispatch some thunk action you want ...

  // route the user to one of the routes defined in the main navigator or the navigator of your application module.
  nainNavNavigate("Dummy");
};

We plan to use an observer-pattern instead a manually registering your notifHandler in global pushNotifications.ts

Set up preferences for your push-notifications

Everything is located in the user application module, in /app/user/actions/notifPrefs.ts.

You have to add your notif types in the includeNotifKeysByApp map :

export const includeNotifKeysByApp = [
  {
    appName: "messagerie",
    notifKeys: ["messagerie.send-message"]
  },
  // ... other apps
  {
    appName: "dummy", // Put the corresponding web application name for grouping your notif prefs
    notifKeys: ["dummy.dummy-event", "dummy.dummy-event-2"] // Put the list of grouped notif types
  },
];

Order has an importance, groups will be printed in the same order as defined here.

The notif-pref toggle button will use a new I18n key (see "I18n" section of this documentation): "notif-pref-<YOUR_APPNAME>", with the appName written in the includeNotifKeysByApp map.

We also plan to move the notification preference registration from the user application module to your own application module

Clone this wiki locally