简体   繁体   中英

Android - Apk Inside APK

Let's say I have 2 apps for my school:

student.apk: Student logs in, check grades, check classes time, does a lot of stuff.

teacher.apk: Teacher logs in, lauches grades, attendence list, etc

Is it possible to create just 1 apk, with a login screen, detect whether it is a student or a teacher and than lauch the correct apk?

Basically what I'm asking is whether I can put these 2 apks (student and teacher) inside one code (login.apk).

The apps are totally different, and it would be very difficult to merge than into one, that's why I would like to launch them inside a simple "login.apk"

Not sure if that's possible. But I believe the better approach would be to use Dynamic Delivery to achieve this. Bundling the Teacher and Student as Dynamic Feature Modules and load them dynamically during runtime based on the login status.

You can find more info here : https://developer.android.com/studio/projects/dynamic-delivery

And a tutorial here : https://medium.com/mindorks/dynamic-feature-modules-the-future-4bee124c0f1

Yes it should be possible. I haven't tested it though. Make a third app (login.apk) which contains both student.apk and teacher.apk. As soon as the user logged in within login.apk, the correct sub apk can be exported/saved from the project to the device internal/external storage (read and write permission required for login.apk), then just launch the exported apk from login.apk by opening it -> Package installer will install it (user interaction required).

I would suggest playing around with intents: the concept is simple, put the login part in one of the two apps (in this example, it will be the student app). when attempting to login, depending on the response from the server, if it is a student account, then it will simply login, otherwise, if it is a teacher account, you will verify if the teacher app is installed. if it is installed you will simply launch it and pass the needed parameters in an intent, otherwise, open the play store and install the needed app. Here is the code for that:

    try {
        //launch the app if it exists 
        Intent intent = new Intent("teacher app signature here");
        intent.putExtra("some_parameter_name", "parameter value");
    } catch (Exception e) {
        // here is the case where the app is not installed
        Uri marketUri = Uri.parse("market://details?id=teacher app signature here");
        Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
        startActivity(marketIntent);
    }

on teacher app, you will need to intercept this intent and its parameters:

    String param= (String) getIntent().getSerializableExtra("some_parameter_name");

you can then save the needed variables in the shared preferences to make sure the user stays connected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM