Question

I am going to implement plugin pattern in my Android application.

Right now I have created:

public abstract class PluginReceiver extends BroadcastReceiver

In an external plugin there is for example

public class SmsPluginReceiver extends PluginReceiver

PluginReceiver class contains also a few methods like getIcon, getName and so on.

SmsPluginReceiver is registered in AndroidManifest.xml as a receiver with specified intent-filter action:

<receiver android:name=".plugin.sms.SmsPluginReceiver">
    <intent-filter>
        <action android:name="hsz.project.plugin" />
    </intent-filter>
</receiver>

In main application I am searching for all available plugins with PackageManager:

PackageManager manager = getPackageManager();
Intent intent = new Intent("hsz.project.plugin");
List<ResolveInfo> matches = manager.queryBroadcastReceivers(intent, 0);

and I got one ResolveInfo object.

I do not know at all what should I do with it - how to access SmsPluginReceiver data (icon, name, ...) ?

Was it helpful?

Solution

A plug-in architecture in Android can be REAL tricky. How tricky depends on what approach you need. I had a project where they wanted to integrage plug-in fragments into the main apps Activity. If you take that approach, the plug-ins will have to be signed with the same key as the main app.

If you can integrate plug-ins by simply launching activities, then I would recommend using PendingIntents. Somehow, you have to get your plug-in to register the PendingIntents into plug-in slots to they can be activated. I used package manager to identify new plug-ins, sent it an intent instructing it to register itself, then exposed a ContentProvider so it could register itself. I then called the PendingIntent's it registered to integrate it into the app experience.

Is that the information you're looking for?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top