Write an application that can use plugins

I am trying to find a way to have plugins in the application.

My goal is to have a main application and offer plugins that can be downloaded to the market. (It could be anything, weather, a radio player, etc.)

Plugins will not interact with each other, so the main application is more like a directory of several applications with the SDK view that plugins use.

There is an example of Tic Tac Toe in the Android document, but the main application requires the main application to declare an external library. My desire is that the main application detects new installed plugins and displays them.

I found this other question , but no answer.

Is there any way to do this?

Edit: There are also apps that can be unlocked by buying another app on the market. How do they work? I have not found anything interesting yet. You know what you find when you open the โ€œAndroid unlockโ€ :)

+7
source share
3 answers

You can use PackageManager to search for another application. If you know the package names of all the "plugins", you can simply check them for each of them in this way.

PackageManager pm = getPackageManager(); try { ApplicationInfo appInfo = pm.getApplicationInfo("com.package.name.your.looking.for", 0); //if we get to here then the app was found, do whatever you need to do. } catch (NameNotFoundException e) { //app was not found } 
+2
source

This is a little cleaner, so you don't need to use a catch try block. In addition, this avoids the fact that someone creates the application of the same name and manually installs it on their phone.

 public boolean checkIfAllowed() { PackageManager pm = getPackageManager(); int match = pm.checkSignatures("your.first.package", "your.second.package"); if (match == PackageManager.SIGNATURE_MATCH) { Log.d("ALLOWED?", "signatures match"); return true; } else { Log.d("ALLOWED?", "signatures don't match"); return false; } } 
+4
source

if you want to separate the main application from the plugins (using PackageManager.getApplicationInfo (package, int) MainApp needs to know which package to look for), you can accept this scheme: during execution, MainApp sends the broadcast intent, which each plugin should listen to (by contract ) In response, each plugin sends a direct intent to the MainApp component, which logs information about the available plugins and how to talk to them. This way you do not need to update MainApp every time a new plugin is created.

+2
source

All Articles