Example usage for android.os PowerManager isIgnoringBatteryOptimizations

List of usage examples for android.os PowerManager isIgnoringBatteryOptimizations

Introduction

In this page you can find the example usage for android.os PowerManager isIgnoringBatteryOptimizations.

Prototype

public boolean isIgnoringBatteryOptimizations(String packageName) 

Source Link

Document

Return whether the given application package name is on the device's power whitelist.

Usage

From source file:com.google.transporttracker.TrackerActivity.java

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);//from   w  w  w  .  ja  v  a2 s  . c om
    }
    startService(new Intent(this, TrackerService.class));
}

From source file:aenadon.wienerlinienalarm.activities.MainActivity.java

private boolean shouldShowDozeDialog(boolean batteryReminderDismissed) {
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
        return false;
    }//from   w  w w. j a v  a  2  s . com
    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);

    boolean hasNotWhitelistedApp;
    if (pm != null) {
        hasNotWhitelistedApp = !pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID);
    } else {
        Log.e("PowerManager is null");
        hasNotWhitelistedApp = true;
    }

    return hasNotWhitelistedApp && !batteryReminderDismissed;
}

From source file:com.bluewatcher.activity.BlueWatcherActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_blue_watcher);

    // ??????/*from   www .  j av a  2 s. c  o  m*/
    String[] str = new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA,
            Manifest.permission.READ_CONTACTS, Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.ACCESS_COARSE_LOCATION, };
    for (String s : str) {
        if (checkSelfPermission(s) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, str, 1);
        }
    }

    PowerManager powerManager = getSystemService(PowerManager.class);
    if (!powerManager.isIgnoringBatteryOptimizations(getPackageName())) {
        Intent intent = new Intent(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
        intent.setData(Uri.parse("package:" + getPackageName()));
        startActivity(intent);
    }

    //????????????this?????
    //Context.getApplicationContext()???
    Context context = this.getApplicationContext();
    //??????????????
    //???????????????????
    //???????
    Thread.setDefaultUncaughtExceptionHandler(new CsUncaughtExceptionHandler(this, context));

    checkLicensing();
    checkBleSupported();

    NotificationAccessLauncher.requestAccess(this);
    ConfigurationManager.initialize(getPreferences(Context.MODE_PRIVATE));
    PhoneFinderConfigManager.resetFindMeFlag();

    boolean bluetoothEnabled = isBluetoothEnabled();
    if (bluetoothEnabled) {
        initializeBlueWatcher();
    }
}

From source file:com.lchtime.safetyexpress.ui.chat.hx.activity.ContactActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String packageName = getPackageName();
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
            Intent intent = new Intent();
            intent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);//from  ww  w .  jav  a2  s .  c  o  m
        }
    }

    //make sure activity will not in background if user is logged into another device or removed
    if (savedInstanceState != null && savedInstanceState.getBoolean(Constant.ACCOUNT_REMOVED, false)) {
        DemoHelper.getInstance().logout(false, null);
        finish();
        startActivity(new Intent(this, LoginUI.class));
        return;
    } else if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) {
        finish();
        startActivity(new Intent(this, LoginUI.class));
        return;
    }
    setContentView(R.layout.em_activity_main);
    // runtime permission for android 6.0, just require all permissions here for simple
    requestPermissions();

    initView();

    showExceptionDialogFromIntent(getIntent());

    inviteMessgeDao = new InviteMessgeDao(this);
    UserDao userDao = new UserDao(this);
    contactListFragment = new ContactListFragment();
    currentTabIndex = 1;
    getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, contactListFragment)
            .show(contactListFragment).commit();

    //register broadcast receiver to receive the change of group from DemoHelper
    registerBroadcastReceiver();

    EMClient.getInstance().contactManager().setContactListener(new MyContactListener());
    //debug purpose only
    registerInternalDebugReceiver();
}

From source file:com.hyphenate.chatuidemo.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String packageName = getPackageName();
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
            Intent intent = new Intent();
            intent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);/*from   w  w  w.  ja  va 2 s  . co m*/
        }
    }

    //make sure activity will not in background if user is logged into another device or removed
    if (savedInstanceState != null && savedInstanceState.getBoolean(Constant.ACCOUNT_REMOVED, false)) {
        DemoHelper.getInstance().logout(false, null);
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    } else if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) {
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    }
    setContentView(R.layout.em_activity_main);
    // runtime permission for android 6.0, just require all permissions here for simple
    requestPermissions();

    initView();

    //umeng api
    MobclickAgent.updateOnlineConfig(this);
    UmengUpdateAgent.setUpdateOnlyWifi(false);
    UmengUpdateAgent.update(this);

    showExceptionDialogFromIntent(getIntent());

    inviteMessgeDao = new InviteMessgeDao(this);
    UserDao userDao = new UserDao(this);
    conversationListFragment = new ConversationListFragment();
    contactListFragment = new ContactListFragment();
    SettingsFragment settingFragment = new SettingsFragment();
    fragments = new Fragment[] { conversationListFragment, contactListFragment, settingFragment };

    getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, conversationListFragment)
            .add(R.id.fragment_container, contactListFragment).hide(contactListFragment)
            .show(conversationListFragment).commit();

    //register broadcast receiver to receive the change of group from DemoHelper
    registerBroadcastReceiver();

    EMClient.getInstance().contactManager().setContactListener(new MyContactListener());
    //debug purpose only
    registerInternalDebugReceiver();
}

From source file:cn.xcom.helper.chat.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String packageName = getPackageName();
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
            Intent intent = new Intent();
            intent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);/*from   w w w.ja v  a 2 s  .  c  o  m*/
        }
    }

    //make sure activity will not in background if user is logged into another device or removed
    if (savedInstanceState != null && savedInstanceState.getBoolean(Constant.ACCOUNT_REMOVED, false)) {
        DemoHelper.getInstance().logout(false, null);
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    } else if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) {
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    }
    setContentView(R.layout.em_activity_main);
    // runtime permission for android 6.0, just require all permissions here for simple
    requestPermissions();

    initView();

    if (getIntent().getBooleanExtra(Constant.ACCOUNT_CONFLICT, false) && !isConflictDialogShow) {
        showConflictDialog();
    } else if (getIntent().getBooleanExtra(Constant.ACCOUNT_REMOVED, false) && !isAccountRemovedDialogShow) {
        showAccountRemovedDialog();
    }

    inviteMessgeDao = new InviteMessgeDao(this);
    userDao = new UserDao(this);
    conversationListFragment = new ConversationListFragment();
    contactListFragment = new ContactListFragment();
    settingFragment = new SettingsFragment();
    fragments = new Fragment[] { conversationListFragment, contactListFragment, settingFragment };

    getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, conversationListFragment)
            .add(R.id.fragment_container, contactListFragment).hide(contactListFragment)
            .show(conversationListFragment).commit();

    //register broadcast receiver to receive the change of group from DemoHelper
    registerBroadcastReceiver();

    EMClient.getInstance().contactManager().setContactListener(new MyContactListener());
    //debug purpose only
    registerInternalDebugReceiver();
}

From source file:com.avcall.app.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String packageName = getPackageName();
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
            Intent intent = new Intent();
            intent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);/*from   ww  w.  j  a  va 2s .c o  m*/
        }
    }

    //make sure activity will not in background if user is logged into another device or removed
    if (savedInstanceState != null && savedInstanceState.getBoolean(Constant.ACCOUNT_REMOVED, false)) {
        AvcallHelper.getInstance().logout(false, null);
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    } else if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) {
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    }
    setContentView(R.layout.em_activity_main);
    // runtime permission for android 6.0, just require all permissions here for simple
    requestPermissions();

    initView();

    if (getIntent().getBooleanExtra(Constant.ACCOUNT_CONFLICT, false) && !isConflictDialogShow) {
        showConflictDialog();
    } else if (getIntent().getBooleanExtra(Constant.ACCOUNT_REMOVED, false) && !isAccountRemovedDialogShow) {
        showAccountRemovedDialog();
    }

    inviteMessgeDao = new InviteMessgeDao(this);
    UserDao userDao = new UserDao(this);
    conversationListFragment = new ConversationListFragment();
    contactListFragment = new ContactListFragment();
    SettingsFragment settingFragment = new SettingsFragment();
    fragments = new Fragment[] { conversationListFragment, contactListFragment, settingFragment };

    getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, conversationListFragment)
            .add(R.id.fragment_container, contactListFragment).hide(contactListFragment)
            .show(conversationListFragment).commit();

    //register broadcast receiver to receive the change of group from DemoHelper
    registerBroadcastReceiver();

    EMClient.getInstance().contactManager().setContactListener(new MyContactListener());
    //debug purpose only
    registerInternalDebugReceiver();
}

From source file:com.abroad.ruianju.im.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String packageName = getPackageName();
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
            Intent intent = new Intent();
            intent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);//from  w ww .  java 2s.  com
        }
    }

    //make sure activity will not in background if user is logged into another device or removed
    if (savedInstanceState != null && savedInstanceState.getBoolean(Constant.ACCOUNT_REMOVED, false)) {
        DemoHelper.getInstance().logout(false, null);
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    } else if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) {
        finish();
        startActivity(new Intent(this, LoginActivity.class));
        return;
    }
    setContentView(R.layout.em_activity_main);
    // runtime permission for android 6.0, just require all permissions here for simple
    requestPermissions();

    initView();

    //umeng api
    //      MobclickAgent.updateOnlineConfig(this);
    //      UmengUpdateAgent.setUpdateOnlyWifi(false);
    //      UmengUpdateAgent.update(this);

    if (getIntent().getBooleanExtra(Constant.ACCOUNT_CONFLICT, false) && !isConflictDialogShow) {
        showConflictDialog();
    } else if (getIntent().getBooleanExtra(Constant.ACCOUNT_REMOVED, false) && !isAccountRemovedDialogShow) {
        showAccountRemovedDialog();
    }

    inviteMessgeDao = new InviteMessgeDao(this);
    UserDao userDao = new UserDao(this);
    conversationListFragment = new ConversationListFragment();
    contactListFragment = new ContactListFragment();
    SettingsFragment settingFragment = new SettingsFragment();
    fragments = new Fragment[] { conversationListFragment, contactListFragment, settingFragment };

    getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, conversationListFragment)
            .add(R.id.fragment_container, contactListFragment).hide(contactListFragment)
            .show(conversationListFragment).commit();

    //register broadcast receiver to receive the change of group from DemoHelper
    registerBroadcastReceiver();

    EMClient.getInstance().contactManager().setContactListener(new MyContactListener());
    //debug purpose only
    registerInternalDebugReceiver();
}

From source file:cn.moon.superwechat.ui.MainActivity.java

private void savePower() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String packageName = getPackageName();
        PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
            Intent intent = new Intent();
            intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);//  w  w  w.  j a  v a 2 s  .  c  o m
        }
    }
}

From source file:cn.ucai.wechat.ui.MainActivity.java

private void savePower() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String packageName = getPackageName();
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
            Intent intent = new Intent();
            intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);//from   w  w w  . j  av  a  2 s .  c  om
        }
    }
}