3

Let's say I have an app which does something (exactly what is irrelevant, as this is a very generic question), and I want other third-party developers to be able to expand the functionality of my application through an add-on like system. Just to give you an example of what I mean, I might develop an SMS app for which someone else could add support for Facebook chat, AIM etc. Is this possible, and if so, how would you go about doing this?

Frxstrem
  • 38,761
  • 9
  • 79
  • 119
  • Do you understand what an Android `Intent` is? – Squonk Jan 20 '12 at 15:00
  • Yes, I am somewhat familiar with them, but I am unaware how they could be used to call code from other activities. I should probably add that what I would want is not to call an activity from another application to do its stuff, but rather to integrate the functionality of another application into my own activities somehow. – Frxstrem Jan 20 '12 at 15:11

3 Answers3

3

I'm pretty sure this isn't allowed due to it would allow a 3rd party to circumvent the permission system in Android. If could get an App to load code not shipped with it then they could get elevated permissions without the user knowing. Even if you had to request permissions when installing the 3rd party plugin those permissions don't have to include the permissions of the App you are augmenting. Therefore, if that code got loaded into the same process as the App it would be allowed to execute at the level of permissions the orignal App had instead of the ones it presented to the user.

Therefore, your only option is to leverage intents, but intents don't have to invoke Activites. You could build a service, or broadcast method to do some processing and give back the results to the original activity. Read up on them and see if you can leverage them. Android's system is a system of collaborating applications not plugins.

http://developer.android.com/guide/topics/intents/intents-filters.html

chubbsondubs
  • 37,646
  • 24
  • 106
  • 138
1

I should probably add that what I would want is not to call an activity from another application to do its stuff, but rather to integrate the functionality of another application into my own activities somehow.

If "functionality" is "UI", that is generally not possible, outside of RemoteViews (the same tech used for app widgets).

If "functionality" is anything else, follow chubbard's answer -- the plugin can expose an API to you and/or you can expose an API to it.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

Integrating the functionality may look a bit different than what you expect. You can leverage the functionality of another application into your own by using an intent to start an activity in the other application. Let's say that your app is app A and all the others on the device are the set of apps : you have to hope that some app in can accept an intent and do what you want. If you want data back, then in addition you have to hope for that functionality as well. If permissions are involved, you have to hope that the application is set up for that as well.

This is always the challenge with cooperation between apps: they all have to have the API for cooperation.

So, the best approach is to use an intent.

Joe Malin
  • 8,621
  • 1
  • 23
  • 18