14

Is it possible to run an application from inside another application? What I want to do is write an app which allows you to chose an app to start, and then displays the activities of this app inside a view.

So in landscape mode, it should look something like this:

enter image description here

The idea behind this is:

I want to be able to start and run a third party activity next to my own activity, and I want to be able to create individual makros with my activity that are controlling the third party activity.

Basically, something like this:

  • Start third party activity from inside my app
  • Start makro recording
  • Do something in third party activity
  • Stop makro recording
  • Use makro whenever you wish

So how can I start and control another activity from inside my own activity?

PKlumpp
  • 3,965
  • 6
  • 31
  • 55
  • It is not possible. Try to use Fragments https://developer.android.com/training/basics/fragments/index.html – resource8218 May 26 '14 at 11:32
  • 6
    well if you say it's not possible, why would fragments help me out? – PKlumpp May 26 '14 at 11:37
  • 4
    Its possible to launch another application from ur own but not in a "view". – Braj May 26 '14 at 11:37
  • ok, that is a great approach, thank you! now I kick the idea of a view out of my head. which direction is my way to go? – PKlumpp May 26 '14 at 11:44
  • Left side Fragment with menu (for example static list with different options) and right side - dynamic change fragments with different informations. – resource8218 May 26 '14 at 13:06
  • 1
    Do you have control over these other applications? what do you want the app to be able to do? why would the app need to be inside your app, do you want to see the menu, or just return to it? Can you describe the actual usecase a bit? – Nanne May 28 '14 at 13:31
  • I can launch an applicatoin in a listview. I created something like that but I am not sure if we are on the same frequency. – The One Jun 04 '14 at 03:39

4 Answers4

21

Unrooted:
Sadly, what you want to achieve does not seem to be possible without rooting the phone, because you can only interact with other apps via intents. Since developers decide how their apps react on specific intents, creating macros this way is nearly impossible.

With rooted phones:

  1. You may want to create a list of all installed apps, you can use

    getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
    

    to retrieve a list of all installed apps.

  2. If the user now selects an app, launch it via an intent and create a system overlay to get all touch/key events (and let the user stop the macro). You can find a way to do this here. Store the x/y-values of the touch-events.
  3. You can recreate the events using MotionEvent#obtain.
  4. Now comes the part where you need a rooted phone (the permission INJECT_EVENTS). Launch the app and inject the events so your macro gets executed. Samplecode:

    Instrumentation m_Instrumentation = new Instrumentation();
    m_Instrumentation.sendPointerSync(motionEvent);
    

    You can find more information about injecting (also keyevents) here.

  5. If you need help to compile your app, these 2 links will help you: How to compile Android Application with system permissions, Android INJECT_EVENTS permission

Community
  • 1
  • 1
Manuel Allenspach
  • 11,309
  • 13
  • 49
  • 72
4

It's not possible to start an application in a View, but you can launch an app from within your app:

 Intent i = getPackageManager().getLaunchIntentForPackage("com.package.ofapp");
 startActivity(i);

//EDIT to your updated question:

After starting the activity from the above code, one way you could start/stop the macro at any time in the new app would be to create a small view overlay on top of the screen.

This overlay would be on top of ALL activities.

Check out the following link: Creating a system overlay window (always on top)

You could write code to start the macro when the View is pressed, and then if the button was pressed once and the user presses it again, stop the macro. This would be in the onTouchEvent() method.

Community
  • 1
  • 1
MJ93
  • 4,228
  • 8
  • 27
  • 50
0

Yes, I think it's possible as a app named floating apps does that (WITHOUT ROOT)

Only using some adb commands

https://play.google.com/store/apps/details?id=com.lwi.android.flapps

Biswajit
  • 37
  • 7
-4

Yes its possible if you use Intents. They allow you to move between screens and to launch another different functionality inside the same app. visit coursera for more tutorials on intents

Tumi
  • 97
  • 1
  • 12