本文整理汇总了Java中android.os.PowerManager.isIgnoringBatteryOptimizations方法的典型用法代码示例。如果您正苦于以下问题:Java PowerManager.isIgnoringBatteryOptimizations方法的具体用法?Java PowerManager.isIgnoringBatteryOptimizations怎么用?Java PowerManager.isIgnoringBatteryOptimizations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.PowerManager
的用法示例。
在下文中一共展示了PowerManager.isIgnoringBatteryOptimizations方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkAndAskForBatteryOptimization
import android.os.PowerManager; //导入方法依赖的package包/类
private void checkAndAskForBatteryOptimization() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !getPrefDone(BATTERY_ASKED_PREF)) {
PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
String packageName = getPackageName();
// this below does not seems to work on my device
if (!powerManager.isIgnoringBatteryOptimizations(packageName)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.battery_optimization_request))
.setPositiveButton(getString(R.string.yes), batteryDialogClick)
.setNegativeButton(getString(R.string.no), batteryDialogClick)
.show();
setPrefDone(BATTERY_ASKED_PREF);
}
}
}
示例2: doPower
import android.os.PowerManager; //导入方法依赖的package包/类
public void doPower() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
String packageName = getPackageName();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (!pm.isIgnoringBatteryOptimizations(packageName)) {
try {
//some device doesn't has activity to handle this intent
//so add try catch
Intent intent = new Intent();
intent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);
} catch (Exception e) {
}
}
}
}
示例3: isInDozeWhiteList
import android.os.PowerManager; //导入方法依赖的package包/类
/**
* Check this app is in system doze whitelist.
* @param context Context param
* @return is in whitelist, always true when pre-marshmallow
*/
@TargetApi(Build.VERSION_CODES.M)
public static boolean isInDozeWhiteList (Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return true;
PowerManager powerManager = context.getSystemService(PowerManager.class);
return powerManager.isIgnoringBatteryOptimizations(context.getPackageName());
}
示例4: checkDozeModeWhiteList
import android.os.PowerManager; //导入方法依赖的package包/类
/**
* Checks whether the app is currently on the system white-list, i.e. if the OS would allow execution even when in Doze mode.
* Note that it makes sense to check this only on API 23 (Android 6.0) because the battery optimization API is not available in previous versions.
* For all pre-Marshmallow APIs, this method will return {@code true}.
*
* @param context Which context to use to check
* @return The value of {@link PowerManager#isIgnoringBatteryOptimizations(String)}
*/
@SuppressWarnings("unused")
public static boolean checkDozeModeWhiteList(@NonNull final Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
} else {
final PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
return powerManager.isIgnoringBatteryOptimizations(context.getPackageName());
}
}
示例5: startLocationService
import android.os.PowerManager; //导入方法依赖的package包/类
private void startLocationService() {
// Before we start the service, confirm that we have extra power usage privileges.
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
Intent intent = new Intent();
if (!pm.isIgnoringBatteryOptimizations(getPackageName())) {
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
}
startService(new Intent(this, TrackerService.class));
}
示例6: requestChangeBatteryOptimizations
import android.os.PowerManager; //导入方法依赖的package包/类
private void requestChangeBatteryOptimizations ()
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent intent = new Intent();
String packageName = getActivity().getPackageName();
PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
if (pm.isIgnoringBatteryOptimizations(packageName))
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
else {
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
}
getActivity().startActivity(intent);
}
}
示例7: isIdleMode
import android.os.PowerManager; //导入方法依赖的package包/类
protected boolean isIdleMode(final Context context) {
final String packageName = context.getPackageName();
final PowerManager manager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
boolean isIgnoringOptimizations = manager.isIgnoringBatteryOptimizations(packageName);
return manager.isDeviceIdleMode() && !isIgnoringOptimizations;
}
示例8: batteryOptimizing
import android.os.PowerManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
public static boolean batteryOptimizing(Context context) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
return !pm.isIgnoringBatteryOptimizations(context.getPackageName());
}