当前位置: 首页>>代码示例>>Java>>正文


Java PowerManager.isIgnoringBatteryOptimizations方法代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:ruuvi,项目名称:com.ruuvi.station,代码行数:17,代码来源:MainActivity.java

示例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) {
            }
        }
    }
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:18,代码来源:LoginActivity.java

示例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());
}
 
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:13,代码来源:PushServiceAccessibility.java

示例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());
    }
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:18,代码来源:SillyAndroid.java

示例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));
}
 
开发者ID:ayushghd,项目名称:iSPY,代码行数:12,代码来源:TrackerActivity.java

示例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);
    }
}
 
开发者ID:guardianproject,项目名称:haven,代码行数:16,代码来源:SettingsFragment.java

示例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;
}
 
开发者ID:datalink747,项目名称:Rx_java2_soussidev,代码行数:7,代码来源:MarshmallowNetworkObservingStrategy.java

示例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());
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:6,代码来源:Util.java


注:本文中的android.os.PowerManager.isIgnoringBatteryOptimizations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。