本文整理匯總了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());
}