Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

android - App inside an app

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...