Add my app to AutoStart apps list in android programmatically

对着背影说爱祢 提交于 2019-12-06 17:48:20

问题


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

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


回答1:


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




回答2:


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);
    }



回答3:


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.



来源:https://stackoverflow.com/questions/41791150/add-my-app-to-autostart-apps-list-in-android-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!