當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。