Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add my app to AutoStart apps list in android programmatically

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

like image 982
asmgx Avatar asked Jan 22 '17 12:01

asmgx


People also ask

How do I get apps to start automatically on Android?

On the Home screen, tap (*) - [Settings] - [Other settings]. The [ ] icon is not displayed on the screen of some Android devices. If the [ ] icon is not displayed on your screen, press the main menu button located outside of the screen. Turn on/off the [Automatically start the app] option.

How do I set autostart permission in android programmatically?

There's no way to find out whether the Auto-start option is enabled or not. You can manually check under Security permissions => Autostart => Enable Autostart .

How do I enable autostart for my app in vivo programmatically?

You can go to Settings>More settings>Permission management(Applications)>Autostart to turn on/off the app switch. For Funtouch OS 2.6 and lower version: Go to i Manager>App manager>Autostart manager to turn on/off the app switch.


4 Answers

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);
    }
like image 122
Karan sharma Avatar answered Oct 03 '22 10:10

Karan sharma


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

like image 41
Akki Avatar answered Oct 03 '22 09:10

Akki


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.

like image 44
galex Avatar answered Oct 03 '22 09:10

galex


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();
    }
like image 33
Wasi Sadman Avatar answered Oct 03 '22 08:10

Wasi Sadman