Delegate text transformation to “plugin” Android apps, not known in advance

前端 未结 2 932
野的像风
野的像风 2021-01-14 09:21

Context

Our app shows an HTML flashcard to the user.
We have added several layers of \"filters\" to satisfy different groups of users:

  • To satisfy
相关标签:
2条回答
  • 2021-01-14 09:49

    To know apps which have a broadcast reciever with THEAPPTRANSFORM as filter, you can use below code

    PackageManager pm = getPackageManager();
        Intent intent = new Intent("THEAPPTRANSFORM");
        List<ResolveInfo> info = pm.queryBroadcastReceivers(intent, 0);
        for (ResolveInfo resolveInfo : info) {
    
            Log.e("apps", "packages = " + resolveInfo.activityInfo.packageName);
        }
    
    0 讨论(0)
  • 2021-01-14 09:52

    You need a dynamically installed plugin which is not part of your application. I think you have a few options for this.

    Solution 1: Scripting

    Ship a scripting language interpreter with your app. (eg. ruby - http://ruboto.org/). Create an interface for executing these scripts. Make a central database of such scripts, or load them from external storage. Now, you can execute these scripts and get the required result.

    Solution 2: AIDL

    Use a remote service in the plugin apps. Provide an AIDL for third parties to develop apps with a remote service with that AIDL. Such services should also conform to an intent filter defined by you. Now you can use packagemanager to find such services, select one and connect to it. Now you can call all the AIDL methods. This will be inter process communication using binder, for your application this will be a synchronous call. (see this SO question for details - Access remote service in different application)

    Downside to this approach is that all these services need to be running when your app is running, so you have to handle the starting/stopping of these services. It will also affect the power consumption if the services are running in the background.

    Solution 3: Broadcast/receiver

    Third party installed apps that have a broadcast receiver with an intent filter for custom intent defined by you. Also, your app needs to have a broadcast receiver with a custom intent that the plugins can call with the result. Now, say you want to call a third party plugin for some transformation, you have to do this:

    Use packagemanager to find all the third party apps conforming to your custom intent. Send a broadcast with extradata about transformation. Handle the transformation in the broadcast receiver of the plugin app. Once transformation is done, send a broadcast with result to the original app.

    This option is entirely asynchronous, and it may take any amount of time to execute with no guaranties.

    0 讨论(0)
提交回复
热议问题