Library for developing Plugin for NotiSender
There is a live demo of the plugin! Download the APK or clone the project and build: PluginShowcase
Plugins are full-blown external apps which allow developers to add to the event, states and actions which NotiSender natively supports. Plugins can also easily be added to existing apps via an extra broadcast receiver (for signalling) and activity (to allow the user to edit their data).
Some important characteristics are:
- the plugin UI is presented via the NotiSender UI just like native NotiSender functions (eg. TelephonyPlugin)
- the plugin developer needs no contact with the NotiSender developer to write, change, publish and/or sell their plugin app
By default, NotiSender and the plugin communicate through BroadcastReceiver, Android's interprocess Pub/Sub implementation.
To communicate with other devices, NotiSender uses SyncProtocol with FCM as a backend to receive/send data.
The following is an example of the process for getting remote data.
- the plugin in Device#1 requests data from the NotiSender in Device#1.
- Device#1's NotiSender sends the data request information over the protocol.
- Device#2's NotiSender receives the requested data and sends it to Device#2's plugin.
- Set the data to be sent in Device#2's plugin and send it to Device#1 in the same way as in steps 1-3.
-
request Device List: Get a list of paired devices from NotiSender.
-
request Remote Action: Run a remote task from the same plugin installed on another device.
-
request & response Remote Data: Get specific data from the same plugin installed on different devices.
-
request Preferences: Gets the Preference value stored in NotiSender.
-
request Service Status: Check the service status of NotiSender.
Now NotiSender can hand over network demands occured by NotiSender to Third-party plugin application, So that network transmitting/receiving action can be processed through a desired network (e.g. custom XMPP server, etc.)
Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.choiman1559:NotiSender-PluginLibrary:Tag'
}
Step 1. Add Application class to your application project.
Step 2. Inheritance custom PluginResponse
class to receive remote tasks
For reference: PluginResponses.java
//Plugin Data Handling Class
//Warning: All methods in this class are called "unexpectedly" in the background, not on the UI thread.
public class PluginResponses implements PluginResponse {
@Override
public void onReceiveRemoteActionRequest(Context context, PairDeviceInfo deviceInfo, String taskType, String args) {
//Handling Remote Work Requests
}
@Override
public void onReceiveRemoteDataRequest(Context context, PairDeviceInfo deviceInfo, String requestedDataType) {
//Handling Remote Data Sending Requests
//The requested data must be replied through the PluginAction.responseRemoteData method.
//Return data to the plugin here
PluginAction.responseRemoteData(context, deviceInfo, requestedDataType, /* Your data to respond */);
}
@Override
public void onReceiveException(Context context, Exception e) {
//Receive and handle exceptions thrown by plugins here
}
}
Step 3. Initializing plugin in your Application class For reference: Applications.java
//Plugin initialization when application is first run
//Due to some technical issues, you need to launch any activity in your app at least once to start the plugin for the first time.
public class Applications extends Application {
@Override
public void onCreate() {
super.onCreate();
//Initialize the plugin
Plugin plugin = Plugin.init(/* instance of PluginResponse-implement class */);
//For Example:
Plugin plugin = Plugin.init(new PluginResponses());
//Setting plugin options
plugin.setPluginTitle(/* Your plugin titile */);
plugin.setPluginDescription(/* Your plugin description */);
plugin.setAppPackageName(/* Plugin application's package name */);
plugin.setPluginReady(/* boolean */);
plugin.setSettingClass(/* Class<?> */);
plugin.setRequireSensitiveAPI(/* boolean*/);
//Setting custom network provider options
try {
plugin.setNetworkProvider(CustomNetProvider.class);
plugin.getNetworkProvider().setProviderName("Plugin Showcase");
} catch (IllegalAccessException | InstantiationException e) {
throw new RuntimeException(e);
}
}
}
Method | Argument Type | Description |
---|---|---|
setPluginTitle | String | The title of the plugin as it will appear in NotiSender |
setPluginDescription | String | Description of the plugin as it will appear in NotiSender |
setAppPackageName | String | The plugin's application package name |
setPluginReady | boolean | Whether the plugin is ready for use (e.g. false if required permissions are not granted) Note: If the value is false, users will not be able to activate the plugin in NotiSender. |
setRequireSensitiveAPI | boolean | Use of NotiSender's sensitive APIs (e.g. getting Preference data, etc.) Note: When the value is false, an exception is thrown when accessing a sensitive API |
setSettingClass | Class<?> | The name of the component (class) of the activity to be displayed in the "Setting" menu when displaying the plug-in in NotiSender Note: The argument must be a class inheriting "Activity" or "AppCompatActivity" |
All methods below are declared in PluginAction class.
For example: MainActivity.java
public static void requestDeviceList(Context context, DeviceListListener.onReceivedListener callback)
Or, alternatively, use
public static void requestDeviceList(Context context)
with Listener (at DeviceListListener class)
public synchronized static void addOnDataReceivedListener(onReceivedListener mOnReceivedListener)
Argument | Type | Description |
---|---|---|
context | Context |
Context for broadcast processing |
callback | DeviceListListener.onReceivedListener |
A listener object to receive device list data sent by NotiSender. |
public static void requestRemoteAction(Context context, PairDeviceInfo device, String type, String data)
Argument | Type | Description |
---|---|---|
context | Context |
Context for broadcast processing |
device | PairDeviceInfo |
The target device on which the action will be requested |
type | String |
Types of actions to run in other plugins |
data | String |
Additional custom data arguments for action behavior |
public static void requestRemoteData(Context context, PairDeviceInfo device, String type, RemoteDataListener.onReceivedListener callback) {
Or, alternatively, use
public static void requestRemoteData(Context context, PairDeviceInfo device, String type)
with Listener (at RemoteDataListener class)
public synchronized static void addOnDataReceivedListener(onReceivedListener mOnReceivedListener)
Argument | Type | Description |
---|---|---|
context | Context |
Context for broadcast processing |
device | PairDeviceInfo |
The target device on which the data will be requested |
type | String |
Types of data to request in other plugins |
callback | RemoteDataListener.onReceivedListener |
A listener object to receive data sent by NotiSender. |
public static void requestPreferences(Context context, String key, PrefsDataListener.onReceivedListener callback)
Or, alternatively, use
public static void requestPreferences(Context context, String key)
with Listener (at PrefsDataListener class)
public synchronized static void addOnDataReceivedListener(onReceivedListener mOnReceivedListener)
Argument | Type | Description |
---|---|---|
context | Context |
Context for broadcast processing |
key | String |
Key of preference to get from NotiSender |
callback | PrefsDataListener.onReceivedListener |
A listener object to receive data sent by NotiSender. |
Note: For security reasons, preference requests for the following keys are restricted
FirebaseIIDPrefix
, GUIDPrefix
, MacIDPrefix
, AndroidIDPrefix
, ApiKey_Billing
, ApiKey_FCM
, ApiKey_Pushy
, UID
, EncryptionPassword
public static void requestServiceStatus(Context context, ServiceStatusListener.onReceivedListener callback)
Or, alternatively, use
public static void requestServiceStatus(Context context)
with Listener (at ServiceStatusListener class)
public synchronized static void addOnDataReceivedListener(onReceivedListener mOnReceivedListener)
Argument | Type | Description |
---|---|---|
context | Context |
Context for broadcast processing |
callback | ServiceStatusListener.onReceivedListener |
A listener object to receive data sent by NotiSender. |