Android examples for Hardware:Battery
Get the intent to either request ignore battery optimization or open battery optimization settings depend on whether the battery optimization is already disabled for the application
//package com.java2s; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.os.Build; import android.provider.Settings; public class Main { @TargetApi(Build.VERSION_CODES.M)//w ww .jav a 2 s. c om // public static Intent getBatteryOptimizationIntent(Context context) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); return intent; } }