0

AppA and AppB can be installed from the Play Store.

From AppA, I want to check if AppB is installed. That is possible and already answered.

If AppB is installed, I want to access java functions AppBFunctionInterface of AppB from AppA.

AppA was compiled with that interface AppBFunctionInterface.

Is it possible in Android?

I create an Intent for AppB. But then how do I get the reference to AppBFunctionInterface ? I don't want AppB to show anything. I just want AppA to access functions provided by AppB code. AppA knows the Activity name of AppB as a String "com.me.appbactivity".

In some ways, you could see AppB as a "library application".

Mordan
  • 337
  • 3
  • 12

2 Answers2

0

This isn't something you'd normally do. Its not something you'd normally do in a desktop app either- what do you do if AppB isn't installed? Just not run?

What you can do is run a service in AppB. Using AIDL you can pass simple commands to the service. But that's the closest you can get.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Use Case Example: I have one AppB that does Morse Code with the Lamp. I have another AppA that look up for AppB on demand of the User. If AppB is not installed, request installation from user. Afterwards, AppB functionality can be seamlessly used from AppA. The rationale is to avoid cramming all my Apps into a single App. Some users might not use all the functionnality – Mordan Dec 12 '16 at 13:29
  • If User requests AppB functionality from AppA and User hasn't installed or does not want to install AppB, functionality is not available, AppA continues to run without issues. – Mordan Dec 12 '16 at 13:34
  • I am going to look into the AIDL. Binder and Messenger might do the trick. Seems like IPC is overkill though! I don't want AppB processes to run. Just want to use their Java Classes :) – Mordan Dec 12 '16 at 13:40
0

First create a library project that contains the common functionality. You can either add the project as a dependency or copy the aar across to the both projects into the libs folder and include it.

Have a look at,

https://developer.android.com/studio/projects/android-library.html

How to include aar files used in library projects in main project in Android

That would be the right approach. Unless you want real time communication between the applications. If you do, then as Gabe suggested; you will need to implement AIDL which supports interprocess communication.

https://developer.android.com/guide/components/aidl.html

Community
  • 1
  • 1
Hades
  • 3,916
  • 3
  • 34
  • 74
  • i want dynamic class loading at runtime from secured signed code from an installed app. Eclipse does that with OSGi. This question http://stackoverflow.com/questions/60764/how-should-i-load-jars-dynamically-at-runtime show how to do it in desktop – Mordan Dec 12 '16 at 13:44
  • @Mordan I don't think you can do that especially if it uses proguard – Hades Dec 12 '16 at 22:31