Create “Battery usage” intent android

六月ゝ 毕业季﹏ 提交于 2019-11-28 00:04:00

Code is as follows:

Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(powerUsageIntent, 0);
// check that the Battery app exists on this device
if(resolveInfo != null){
    startActivity(powerUsageIntent);
}

Base on the handful code of @Chris Lacy , I wrapped the code to static method that you call to open this screen:

public static void openBatteryUsagePage(Context ctx){
    Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
    ResolveInfo resolveInfo = ctx.getPackageManager().resolveActivity(powerUsageIntent, 0);
    // check that the Battery app exists on this device
    if(resolveInfo != null){
        ctx.startActivity(powerUsageIntent);
    } else
        Toast.makeText(ctx, R.string.not_found, Toast.LENGTH_LONG).show();
} 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!