Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write an application that can use plugins

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

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

The plugins would not interact with each other, so the core application is more like a directory of multiple applications with kind of a SDK that the plugins use.

There is the Tic Tac Toe example in the Android doc, but the requires the main app to declare the external lib. My wish is that the core app detects the new installed plugins and shows them.

I found this other question but there is no answer.

Is there a way to do that?

Edit: There are also applications that can be unlocked by buying another app on the market. How do they work? I could not find anything interesting yet. You know what you find when you google "android unlock" :)

like image 217
Jonas Schmid Avatar asked Dec 29 '10 13:12

Jonas Schmid


People also ask

What are application plugins?

Plug-in applications are programs that can easily be installed and used as part of your Web browser. Initially, the Netscape browser allowed you to download, install, and define supplementary programs that played sound or motion video or performed other functions.

What is plugin on mobile app?

A plug-in is a one which adds as an extra feature or the functionality to an application. Moreover, installing these plugins is much easier than developing the element in the mobile application. The major reasons why Plugins can be a greater choice because: Easy for anyone to use without any technical knowledge.

How do app plugins work?

A plugin is a piece of software that acts as an add-on to a web browser and gives the browser additional functionality. Plugins can allow a web browser to display additional content it was not originally designed to display.


3 Answers

This is a little cleaner, so you don't have to use a try catch block. Also, this avoids someone creating an app with the same name and manually installing 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;
    }
}
like image 190
steve Avatar answered Oct 12 '22 05:10

steve


You can use PackageManager to look for another application. If you know the package names of all of the 'plugins' then you can just check for each of them 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
                    }
like image 28
FoamyGuy Avatar answered Oct 12 '22 04:10

FoamyGuy


if you want to decouple the main app from the plugins (using PackageManager.getApplicationInfo(package, int) MainApp has to know which package to search for) you can adopt this scheme: at run time MainApp send a broadcast intent that every plugin has to listen to (by contract). In response, every plugin send a direct intent to a component of MainApp that register information about available plugins and how to talk to them. In this way, you don't have to update MainApp each time a new plugin is created.

like image 31
andijcr Avatar answered Oct 12 '22 04:10

andijcr