Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a simulated Android environment within my application

Tags:

As the title says, I need to create a simulated Android environment within my app. I need to be able to install applications on this environment without installing them on the device.

I know it's possible because this app does it.

I've been searching for a while and I know the app does it by creating an Android environment, but I don't seem to find a lead on how to do it.

EDIT:

I found another app that can do it

Parallel Space

like image 358
Muhammad Ashraf Avatar asked Jul 14 '16 07:07

Muhammad Ashraf


People also ask

How do I simulate an app on Android?

Run your app on the emulator After you have created an Android Virtual Device (AVD), you can start the Android Emulator and run an app in your project: In the toolbar, select the AVD that you want to run your app on from the target device drop-down menu. Click Run.

What is emulator and AVD in Android?

An Android emulator is an Android Virtual Device (AVD) that represents a specific Android device. You can use an Android emulator as a target platform to run and test your Android applications on your PC. Using Android emulators is optional.

How can I use my phone as an emulator in Android Studio?

Emulator for native development with Android StudioIn the Android Studio toolbar, select your app from the run configurations drop-down menu. From the target device drop-down menu, select the device that you want to run your app on. Select Run ▷. This will launch the Android Emulator.


1 Answers

It depends to what degree you need to run the app and what constitutes "installing" the app. Keep in mind that an .apk file is just a java .jar file with some extra data tucked away in various places.

In order to run portions of an Android application without installing it, you will need to

  1. Open and parse the apk. This APKParser class might be a good place to start.
  2. Request any permissions which the app in question requires which aren't already requested by your app. In older versions of Android you would just have to request all possible permissions to start with, but with newer versions you can requestPermissions to make the actual permission request dialog when convenient.
  3. Copy the classes.dex from the application into your data folder. If it uses any common classes which you also use, you'll probably want to nuke these out of the dex file so that you don't have class loading conflict, or else be very, very careful with class loaders.
  4. Load the dex file with a DexFileLoader.
  5. At this point you can load just about any code in the apk, but you won't be able to do a straight load of the Activities, since they're not defined in your AndroidManifest.xml. Instead, you'll need to create a "facade" Activity that hosts the actual activity in reflection and wires up things like the context into the reflected Activity.

These steps should probably work to run at least simple apps without installing them.

like image 83
jwriteclub Avatar answered Oct 03 '22 02:10

jwriteclub