1

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, ...) ?

Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
hsz
  • 148,279
  • 62
  • 259
  • 315
  • Not sure it's possible. You might need to send an ordered broadcast in order to retrieve this kind of information from each of the registered receivers - http://developer.android.com/reference/android/content/Context.html#sendOrderedBroadcast%28android.content.Intent,%20java.lang.String,%20android.content.BroadcastReceiver,%20android.os.Handler,%20int,%20java.lang.String,%20android.os.Bundle%29. Otherwise you might need to setup your own registry of receivers. – Paul Grime Feb 15 '12 at 12:54

1 Answers1

2

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?

jsmith
  • 4,847
  • 2
  • 32
  • 39