Extension (or plugin) is an android application that integrates with OSSW android application and exposes some properties or allows to invoke some functions.
You can check a source code of sample extension that is available on github
One of the first decisions is to choose a package name for the extension, in the sample plugin it’s:
com.althink.android.ossw.plugins.sample
I will reference this name with %PACKAGE_NAME% placeholder.
Every extension’s AndroidManifest.xml should look like this:
1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="%PACKAGE_NAME%">
4
5 <application
6 android:allowBackup="true"
7 android:icon="@drawable/ic_launcher"
8 android:label="@string/app_name"
9 android:theme="@style/AppTheme">
10 <activity
11 android:name=".SamplePluginSettingsActivity"
12 android:label="@string/plugin_name">
13 <intent-filter>
14 <action android:name="%PACKAGE_NAME%.config" />
15 <category android:name="android.intent.category.DEFAULT" />
16 </intent-filter>
17 </activity>
18
19 <provider
20 android:name=".SamplePluginContentProvider"
21 android:authorities="%PACKAGE_NAME%"
22 android:exported="true"
23 android:syncable="false"
24 android:enabled="true"
25 android:label="@string/plugin_name"
26 ><meta-data android:name="com.althink.android.ossw.plugin" android:value="true"></meta-data>
27 </provider>
28
29 <service
30 android:name=".SamplePluginService"
31 android:exported="true">
32 <intent-filter>
33 <action android:name="%PACKAGE_NAME%" />
34 </intent-filter>
35 </service>
36 </application>
37 </manifest>
There are three important definitions:
Extension service is a backend service that is responsible for updating extension properties and handling extension function invocations.
The simplest extension service implementation will look like this:
1 public class SamplePluginService extends Service {
2 private final Messenger mMessenger = new Messenger(new OperationHandler());
3
4 @Override
5 public IBinder onBind(Intent intent) {
6 // perform some initialization
7 return mMessenger.getBinder();
8 }
9
10 private class OperationHandler extends Handler {
11
12 public OperationHandler() {
13 }
14
15 @Override
16 public void handleMessage(Message msg) {
17 super.handleMessage(msg);
18
19 switch (msg.what) {
20 // handle function invocation, msg.what contains function identifier
21
22 // optional function parameter can be accessed by invoking:
23 // String parameter = msg.getData().getString("parameter");
24 }
25 }
26 }
27 }
Extension content provider is a content provider that expose extension API and extension properties (if any). Extension content provider should handle given URIs:
content://%PACKAGE_NAME%/api/properties
Table with definition of extension properties, every row represents single property, table columns are as follows:
content://%PACKAGE_NAME%/api/functions
Table with definition of extension functions, every row represents single function, table columns are as follows:
content://%PACKAGE_NAME%/properties
Table with extension property values, table columns are extension property names and first row values are extension property values. Only one row should be returned.
Extension settings activity is a standard android PreferenceActivity that is responsible for extension configuration.
Extension settings activity should handle “%PACKAGE_NAME%.config” intent action, for sample extension it’s
com.althink.android.ossw.plugins.sample.config
Intent filter definition should look like this:
1 <intent-filter>
2 <action android:name="%PACKAGE_NAME%.config" />
3 <category android:name="android.intent.category.DEFAULT" />
4 </intent-filter>