Android插件模式插件、模式、Android

2023-09-06 17:16:29 作者:心碎了无痕

我要实现我的Andr​​oid应用程序的插件模式。

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

现在,我已经创建了:

public abstract class PluginReceiver extends BroadcastReceiver

在外部插件有例如:

public class SmsPluginReceiver extends PluginReceiver

PluginReceiver 类包含像调用getIcon 的getName 等。

SmsPluginReceiver 的Andr​​oidManifest.xml 注册为具有特定意图筛选器操作接收器:

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);

和我得到了一个 ResolveInfo 对象。

我不知道在所有我应该怎么做吗? - 如何访问 SmsPluginReceiver 数据(图标,名称,...)

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

推荐答案

一个插件架构在Android中才能真正棘手。如何棘手取决于你所需要的方法。我有一个项目,他们想插件片段integrage到主应用中的活动。如果采取这种方法,该插件必须使用相同的密钥作为主应用程序签名。

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.

如果您可以通过简单的发射活动整合插件,那么我会建议使用PendingIntents。不知怎的,你必须让你的插件到PendingIntents注册到插件插槽就可以被激活。我用包管理器,以确定新的插件,它发出的意图,指示它本身注册,然后暴露ContentProvider的,因此它可能注册。然后,我叫的PendingIntent的它注册将其集成到应用体验。

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.

这就是你要找的?信息