1

I would like to integrate an application (lets call this app1), into another application (app2), which will invoke app1 with a button click. What are the possible ways of achieving this, without exposing the source code of app1 to app2. app1 shouldn't be installed as a saperate application, it should be part of app1.

I was thinking to somehow convert app1 to a jar file and integrate it in to app2, is this possible?, or suggest me some ways to achieve the above requirement.

Yashwanth Kumar
  • 28,931
  • 15
  • 65
  • 69
  • Can't you use a special `Intent` from app2 which will start app1? – user Sep 20 '12 at 08:58
  • app1 should be embedded in app2, not as a separate application. – Yashwanth Kumar Sep 20 '12 at 09:31
  • As far as code is concerned , you can load classes from some *.dex file if you can access it as mentioned [here](http://android-developers.blogspot.in/2011/07/custom-class-loading-in-dalvik.html). Do you want to supply whole app2.apk in assets of app1 ? – S.D. Sep 20 '12 at 10:42
  • 3
    "app1 should be embedded in app2, not as a separate application." -- are you the author of app1? If not, do you have a license for app1 that allows for distribution in any fashion, let alone this one? – CommonsWare Sep 20 '12 at 11:04
  • @CommonsWare , yes i am the author of app1, and i do have the licenses required, Integrating app1 in app2, will benefit our both parties, hence the requirement, and i don't want to expose my source code. – Yashwanth Kumar Sep 20 '12 at 11:42
  • @wingman , i don't want to ask the user to install the app1 separately again. – Yashwanth Kumar Sep 20 '12 at 11:43
  • 4
    @YashwanthKumar Android as of now doesn't support app embedding. You can't sneak any full fledged app and make it work in android system without user installing it. Looking as it this way, its a good security measure. – S.D. Sep 20 '12 at 13:42
  • Is this properly explained? You will not use intents because app1 is not installed right? Then, if you can moodify source of app2 why not include app1 classes as a subpackage? – quinestor Sep 28 '12 at 09:09
  • @quinestor, you got my question right, how do i go about creating a sub package, without exposing the code. – Yashwanth Kumar Sep 28 '12 at 13:30

6 Answers6

4

If app 1 has android resource files (layouts,xml drawables etc.) and jar dependencies you cannot avoid exposing them.

If you are willing to expose your resource and external jars you can:

  1. Change app1 to an android library.
  2. Create another library project with the same resources and jars of app1 (without the sources).
  3. Copy the generated jar file out of the app1 library project bin folder to the seconds library project libs folder.

The end result is a library project without the java source files but with the resources, this library project can be used in app B without exposing your java files.

Notice that some re-factoring to app1 might be required.

tomas
  • 236
  • 1
  • 2
  • looks like something which could work, can you explain the answer a little further on how to achieve each of the above steps. – Yashwanth Kumar Oct 02 '12 at 13:37
  • 3rd step, which jar file are you referring to, and how to generate that?. – Yashwanth Kumar Oct 02 '12 at 16:04
  • If you're using eclipse and the ADT plugin, The app1 library project will auto generate a jar file called app1.jar inside the bin folder. You should take this file (which now contains all the app1 classes), and use it as an external jar in the new library project (the one without the sources). – tomas Oct 02 '12 at 16:21
  • All went fine,till i was accessing resources in the app1 projects, it is giving null pointer exception when the code of app1 is invoked which had a line with resource reference (for example, R.id.some_resource, and R is the com.app1packagename.R) – Yashwanth Kumar Oct 02 '12 at 18:29
  • Make sure that the resource exists in the other library project and if still doesn't work try to use use the ressources.getIdentifier() methoed according to this answer: http://stackoverflow.com/questions/4741510/android-import-ressources-from-library-project. – tomas Oct 02 '12 at 21:28
2

As I understand your question app1 is not yours but you want to use its functionality from within your app (app2). If this is the case then you must follow Android's rules of inter-App communications which are the Intents. If app1 is a generic utility application (like a bar-code reader or a picture editor etc) then their needed intents will be well known to you (as a developer) and you can use them without any problem.

Now if app1 is not installed in the users device, you can always do a check and prompt the user for the installation of it. Furthermore, if licensing policy of app1 is not a problem, you can distribute its apk with your application and install it on the user's device.

Here is a code sample to check if an application is installed (Actually it checks if it can be launched therefore is installed):

public static boolean isAppInstalled(Context cx, String packagename) {
    PackageManager pm = cx.getPackageManager();
    Intent i = pm.getLaunchIntentForPackage(packagename);
    return (i != null);
}

As for prompting the user for downloading and install it you may start here

And if you are distributing the apk from within your application you may take a look here on how to launch it.

Finally, about converting an apk to a jar, I don't know if this is possible but if it is it will be some kind of hack which is not the best practice to create an application. On the other hand there are many free android libraries (jar files) out there which are covering a very broad field of functionality and you can integrate them in your application very easy.

Hope this helps...

Community
  • 1
  • 1
ChD Computers
  • 3,135
  • 3
  • 23
  • 33
0

It seems to me the intent system is exactly what you are looking for - the android intents were designed for inter-app communication - this is the standard method for accessing diverse functionality in other installed applications (for example it is the way you would send an image as an email or share it to face book or display it in the installed gallery software).

The intent system allows two way passing of data and is quiet string. Depending on the exact nature of the interaction you choose to publish this interface so other application can interact with you in the same manner.

Elemental
  • 7,365
  • 2
  • 28
  • 33
0

I think that Library project is the answer you seek.

You should set App1 project to be a library project : Right click on project in Eclipse -> properties -> Android -> check isLibrary.

In your APp2 project do: Right click on project in Eclipse -> properties -> Android -> Add -> select App1.

Now your can use anything that's defined in App1 from App2 project.

Givi
  • 3,283
  • 4
  • 20
  • 23
0

After reading your original question and the responses you have provided, to further understand your requirements, it is not possible to accomplish what you want. In fact, that is by design.

As others mentioned, Android provides a specific methodology for inter-application communication via intents, which is clear does not work for you.

Gafanha
  • 101
  • 6
0

I think it's similar a plug-in.It is possible to have a plugin architecture for your application. These links should help you out:

Trung Nguyen
  • 7,442
  • 2
  • 45
  • 87