Add my app to AutoStart apps list in android programmatically
Asked Answered
M

4

19

I want my app to be in the autostart list after installation.

I know when I install an app like (whatsapp) it goes automatically to the autostart list. I want my app to be the same

enter image description here

I tried the code in this question How to Autostart an Android Application?

but unfortunately non of the answers actually made the app autostart.

Not sure if I am doing something wrong

the reason that I need the app be autostart is just to get notifications from the webservice. as the app does not get notifications unless its open or autostart is on

would appreciate your help

thanks

Mow answered 22/1, 2017 at 12:57 Comment(10)
As far as I know there is no real autostart for apps. You can register BroadcastReceiver and so on so your app will automatically react to push messages or intents. Most android smartphones don't have the screen you are showing on the screenshot. This is a custom feature which is mostly used to save battery power.Mannie
You have to use Broadcast Receiver to start your application when the phone boots. Your question still needs more clarity, to answer I need to know whether you want to start a service (in background) or start an activity (foreground). For either case you will need to add broadcast receiverUnriddle
The screen is from MIUI android.. i thought the same feature exist in all androids so apps like whatsapp can get notifications even though user did not start the whatsapp every time they restart the phoneMow
You can try using Broadcast Receiver and check whether it works.Unriddle
@asmgx, did u got the answer or hint, if yes please let me know.Repeated
@TheGreat004 No, no one gave a solution for thatMow
@Mow please comment here if you get a solution. thank you.Knop
@TheGreat004 Did you got any solution?Cailly
@AswathyKR No, as the accepted answer mentioned no solutionMow
Please refere attached link for reference #49473730Conflagration
A
4

Few popular apps run in background without being killed during memory cleanup cycle (many of the popular OEMs customize the stack ROM for battery/memory optimization), because they are "White listed" by these manufactures. For your app you can whitelist it either manually (via corresponding "settings" for the devices) or pragmatically by redirecting users to the corresponding settings page to white list the app.

Please have a look for details here

Asleyaslope answered 1/6, 2019 at 14:17 Comment(0)
U
8

Some of the applications such as Whatsapp and Facebook might have been whiltlisted thats why they have automatic Autostart option enabled.

But i have tried the following code for Xiaomi Devices hope this might help!!

    String manufacturer = "xiaomi";
    if(manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
        //this will open auto start screen where user can enable permission for your app
        Intent intent = new Intent();
        intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
        startActivity(intent);
    }
Undeceive answered 3/4, 2018 at 11:19 Comment(3)
@AbhishekPandya Its depends on your logic but must be before calling the service to get start. Please have a look here: https://mcmap.net/q/37429/-android-how-to-enable-autostart-option-programmatically-in-xiaomi-devicesAsleyaslope
zomato app also auto start then hpw to auto start own android application please help me friendsLeandroleaning
how to check for other manufacturers like Infinix ?Puritanical
V
5

This screen/behaviour is not native to Android, meaning the screen you show comes from a custom rom, probably from a particular manufacturer.

Like you said the answers in the other question do not work but they are the only native way to start an application on boot/start.

Check if the app/custom rom has an API (a particular broadcast receiver to implement, or some SDK...). You can always decompile one of the apps that implement this behaviour to see how they do appear in this menu.

Vani answered 22/1, 2017 at 13:11 Comment(0)
A
4

Few popular apps run in background without being killed during memory cleanup cycle (many of the popular OEMs customize the stack ROM for battery/memory optimization), because they are "White listed" by these manufactures. For your app you can whitelist it either manually (via corresponding "settings" for the devices) or pragmatically by redirecting users to the corresponding settings page to white list the app.

Please have a look for details here

Asleyaslope answered 1/6, 2019 at 14:17 Comment(0)
N
2

I have tried below code to whitelist my app

try {
        final Intent intent = new Intent();
        String manufacturer = Build.MANUFACTURER;
        if ("xiaomi".equalsIgnoreCase(manufacturer)) {
            intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
        } else if ("oppo".equalsIgnoreCase(manufacturer)) {
            intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
            //intent.setComponent(new ComponentName("com.coloros.oppoguardelf", "com.coloros.powermanager.fuelgaue.PowerConsumptionActivity"));
        } else if ("vivo".equalsIgnoreCase(manufacturer)) {
            intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
        } else if ("huawei".equalsIgnoreCase(manufacturer)) {
            intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
        } else {
            // applySubmit(false);
            return;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
Neau answered 19/7, 2021 at 7:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.