如何使我的android应用程序以超省电模式显示

如何使我的android应用程序以超省电模式显示,android,samsung-mobile,power-saving,Android,Samsung Mobile,Power Saving,一些三星设备具有超节能模式,可以关闭wifi,将屏幕灰度化,并将使用限制在几个基本应用程序上 不过,它确实允许您添加一些应用程序,然后可以使用这些应用程序。这些应用包括Facebook和WhatsApp。如何使我的应用程序显示在此列表中?我必须对应用程序进行哪些更改才能将其显示在此列表中?或者该列表是基于三星维护的白名单吗?可能使用该权限。此权限不需要显式用户权限。我们会同意的。尽管这不会阻止用户手动停止应用程序 发件人: 这是一个普通权限:请求它的应用程序将始终处于 已授予权限,用户无需批准或

一些三星设备具有超节能模式,可以关闭wifi,将屏幕灰度化,并将使用限制在几个基本应用程序上


不过,它确实允许您添加一些应用程序,然后可以使用这些应用程序。这些应用包括Facebook和WhatsApp。如何使我的应用程序显示在此列表中?我必须对应用程序进行哪些更改才能将其显示在此列表中?或者该列表是基于三星维护的白名单吗?

可能使用该权限。此权限不需要显式用户权限。我们会同意的。尽管这不会阻止用户手动停止应用程序

发件人:

这是一个普通权限:请求它的应用程序将始终处于 已授予权限,用户无需批准或查看

将应用程序放入设备的白名单

将让您知道该应用程序是否已列入白名单

以下几点说明:

注意:大多数应用程序不应使用此选项;有很多设施 由平台提供,以便应用程序在 各种节能模式。这仅适用于以下特殊应用: 需要以潜在的代价深刻控制自己的执行 用户的电池寿命。请注意,这些应用程序的运行效率非常高 向用户显示为高功率用户的风险 装置

输入:意图的数据URI必须指定应用程序包名称 如图所示,带有“包装”方案。这就是“package:com.my.app”

我不建议滥用它

这里有一个清单

一般来说,你的应用程序不应该出现在白名单上,除非是打瞌睡或应用程序 待机中断应用程序的核心功能或存在技术问题 应用程序无法使用FCM高优先级消息的原因


感谢您提供此最新链接。

解决方案不基于代码,而是基于第三方应用程序,最终用户正在安装UPSM+应用程序

public class UPSM {

private static SQLiteDatabase db;

synchronized public static void CONFIGURE_UPSM(boolean isEnable, String APP_PACKAGE, String APP_LAUNCHER_ACTIVITY) {
    try {
        final String FILE_PATH = "/data/data/com.sec.android.provider.emergencymode/databases/emergency.db";
        final String FILE_PATH_JOURNAL = "/data/data/com.sec.android.provider.emergencymode/databases/emergency.db-journal";
        String command = "adb shell \"su -c cat " + FILE_PATH + "\" > emergency.db";
        Shell.SU.run("chmod 777 " + FILE_PATH);
        Shell.SU.run(command);
        String command_journal = "adb shell \"su -c cat " + FILE_PATH_JOURNAL + "\" > emergency.db-journal";
        Shell.SU.run("chmod 777 " + FILE_PATH_JOURNAL);
        Shell.SU.run(command_journal);
        String COMMAND_ENABLE = "settings put global low_power 1\n" +
                "am broadcast -a android.os.action.POWER_SAVE_MODE_CHANGED --ez mode true\n";
        String COMMAND_DISABLE = "settings put global low_power 0\n" +
                "am broadcast -a android.os.action.POWER_SAVE_MODE_CHANGED --ez mode false\n";
        if (isEnable) {
            Shell.SU.run(COMMAND_ENABLE);
        } else {
            Shell.SU.run(COMMAND_DISABLE);
        }
        File file = new File(FILE_PATH);
        if (file.exists()) {
            if (db == null) {
                db = SQLiteDatabase.openOrCreateDatabase(FILE_PATH, null);
                db = SQLiteDatabase.openDatabase(FILE_PATH, null, SQLiteDatabase.OPEN_READWRITE);
                db.setLockingEnabled(false);
            } else if (!db.isOpen()) {
                db = SQLiteDatabase.openOrCreateDatabase(FILE_PATH, null);
                db = SQLiteDatabase.openDatabase(FILE_PATH, null, SQLiteDatabase.OPEN_READWRITE);
                db.setLockingEnabled(false);
            }
            if (db != null && db.isOpen()) {
                configureLauncherAdd(isEnable, APP_PACKAGE, APP_LAUNCHER_ACTIVITY, db);
                configureLauncherDefault(isEnable, APP_PACKAGE, APP_LAUNCHER_ACTIVITY, db);
                configureWhiteList(isEnable, APP_PACKAGE, db);
                db.close();
                db = null;
            }
        }
    } catch (NullPointerException e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_1");
    } catch (RuntimeException e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_1");
    } catch (OutOfMemoryError e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_1");
    } catch (Exception e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_1");
    }
}

private static void configureLauncherAdd(boolean isEnable, String APP_PACKAGE, String APP_LAUNCHER_ACTIVITY, SQLiteDatabase db) {
    try {
        boolean isExist = false;
        Cursor cursor = db.rawQuery("select * from launcheradd where package like '" + APP_PACKAGE + "' and class like '" + APP_LAUNCHER_ACTIVITY + "'", null);
        if (cursor != null) {
            if (!cursor.isAfterLast()) {
                cursor.moveToFirst();
                long count = cursor.getCount();
                if (count > 0) {
                    isExist = true;
                }
            }
            cursor.close();
        }
        if (!isExist) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("package", APP_PACKAGE);
            contentValues.put("class", APP_LAUNCHER_ACTIVITY);
            contentValues.put("permission", "1111");
            if (isEnable) {
                contentValues.put("mode", 1);
            } else {
                contentValues.put("mode", 0);
            }
            db.insert("launcheradd", null, contentValues);
        } else {
            ContentValues contentValues = new ContentValues();
            if (isEnable) {
                contentValues.put("mode", 1);
            } else {
                contentValues.put("mode", 0);
            }
            String where = "package like '" + APP_PACKAGE + "' and class like '" + APP_LAUNCHER_ACTIVITY + "'";
            db.update("launcheradd", contentValues, where, null);
        }
    } catch (NullPointerException e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_2");
    } catch (RuntimeException e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_2");
    } catch (OutOfMemoryError e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_2");
    } catch (Exception e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_2");
    }
}

private static void configureLauncherDefault(boolean isEnable, String APP_PACKAGE, String APP_LAUNCHER_ACTIVITY, SQLiteDatabase db) {
    try {
        boolean isExist = false;
        Cursor cursor = db.rawQuery("select * from launcherdefault where package like '" + APP_PACKAGE + "' and class like '" + APP_LAUNCHER_ACTIVITY + "'", null);
        if (cursor != null) {
            if (!cursor.isAfterLast()) {
                cursor.moveToFirst();
                long count = cursor.getCount();
                if (count > 0) {
                    isExist = true;
                }
            }
            cursor.close();
        }
        if (!isExist) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("package", APP_PACKAGE);
            contentValues.put("class", APP_LAUNCHER_ACTIVITY);
            contentValues.put("position", 1);
            contentValues.put("fixed", 1);
            if (isEnable) {
                contentValues.put("mode", 1);
            } else {
                contentValues.put("mode", 0);
            }
            db.insert("launcherdefault", null, contentValues);
        } else {
            ContentValues contentValues = new ContentValues();
            if (isEnable) {
                contentValues.put("mode", 1);
            } else {
                contentValues.put("mode", 0);
            }
            String where = "package like '" + APP_PACKAGE + "' and class like '" + APP_LAUNCHER_ACTIVITY + "'";
            db.update("launcherdefault", contentValues, where, null);
        }
    } catch (NullPointerException e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_3");
    } catch (RuntimeException e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_3");
    } catch (OutOfMemoryError e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_3");
    } catch (Exception e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_3");
    }
}

private static void configureWhiteList(boolean isEnable, String APP_PACKAGE, SQLiteDatabase db) {
    try {
        boolean isExist = false;
        Cursor cursor = db.rawQuery("select * from whitelist where pkg like '" + APP_PACKAGE + "'", null);
        if (cursor != null) {
            if (!cursor.isAfterLast()) {
                cursor.moveToFirst();
                long count = cursor.getCount();
                if (count > 0) {
                    isExist = true;
                }
            }
            cursor.close();
        }
        if (!isExist) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("pkg", APP_PACKAGE);
            if (isEnable) {
                contentValues.put("allowflag", 1);
            } else {
                contentValues.put("allowflag", 0);
            }
            db.insert("whitelist", null, contentValues);
        } else {
            ContentValues contentValues = new ContentValues();
            if (isEnable) {
                contentValues.put("allowflag", 1);
            } else {
                contentValues.put("allowflag", 0);
            }
            String where = "pkg like '" + APP_PACKAGE + "'";
            db.update("whitelist", contentValues, where, null);
        }
    } catch (NullPointerException e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_4");
    } catch (RuntimeException e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_4");
    } catch (OutOfMemoryError e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_4");
    } catch (Exception e) {
        StackTraceLog.write(e, "CONFIGURE_UPSM_4");
    }
}

}

//IGNORE StackTraceLog 
通过此应用程序,您可以使任何已安装的应用程序可用于UPSM。
此外,通过该应用程序,您还可以通过“始终启用”、“关闭屏幕时请勿杀戮”等选项控制行为,…

这可能会帮助您有趣的是,facebook处于超节能模式列表:)如果您的应用程序做了大量后台工作,三星的内置电池应用程序将自动将其放入。因此,fe,如果你的应用程序在一项服务中收集位置信息,或者,在将来使用作业调度来设置工作,那么你在该列表中的几率会更高。不过,我不太清楚你为什么会想去那里。似乎是由制造商决定哪些应用程序会出现在列表中,messenger信号也有同样的效果。禁用设备上的电池优化需要用户操作。如果您使用操作\u请求\u忽略\u电池\u优化,他们必须确认对话框,或者自己禁用它。此外,“谷歌播放政策禁止应用程序请求直接豁免Android 6.0+中的电源管理功能(打瞌睡和应用程序待机),除非该应用程序的核心功能受到不利影响。”我最近不得不亲自实施该策略,因此我第一手了解它的工作原理。您已被授予该权限,但该权限仅允许您发送“操作\请求\忽略\电池\优化”意图。此意图将向用户显示一个对话框,询问他们是否要禁用电池优化。我发现了这个对话框的一个例子(上的文本因版本而异),没有,只是在那里找到了图像。声明您请求优化所需的权限并不是授予的,因为将应用程序列入白名单的实际过程是静默的。这是如何请求权限:这不会使我的应用程序在三星Galaxy A5上以超节能模式可用。请解释代码试图如何解决问题中提到的问题。Shell类不可用?这需要一个固定电话吗?