简体   繁体   English

以编程方式将我的应用程序添加到 android 中的自动启动应用程序列表

[英]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.我知道当我安装像 (whatsapp) 这样的应用程序时,它会自动进入自动启动列表。 I want my app to be the same我希望我的应用程序是相同的

在此处输入图片说明

I tried the code in this question How to Autostart an Android Application?我尝试了这个问题中的代码如何自动启动 Android 应用程序?

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谢谢

Some of the applications such as Whatsapp and Facebook might have been whiltlisted thats why they have automatic Autostart option enabled.某些应用程序(例如 Whatsapp 和 Facebook)可能已被列入白名单,这就是它们启用自动自动启动选项的原因。

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

This screen/behaviour is not native to Android, meaning the screen you show comes from a custom rom, probably from a particular manufacturer.此屏幕/行为不是 Android 原生的,这意味着您显示的屏幕来自自定义 rom,可能来自特定制造商。

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...).检查应用程序/自定义 rom 是否具有 API(要实现的特定广播接收器,或某些 SDK...)。 You can always decompile one of the apps that implement this behaviour to see how they do appear in this menu.您始终可以反编译实现此行为的应用程序之一,以查看它们在此菜单中的显示方式。

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.很少有流行的应用程序在后台运行而不在内存清理周期中被杀死(许多流行的 OEM 为电池/内存优化定制堆栈 ROM),因为它们被这些制造商“列入白名单”。 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在此处查看详细信息

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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