Example usage for android.provider Settings ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

List of usage examples for android.provider Settings ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

Introduction

In this page you can find the example usage for android.provider Settings ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS.

Prototype

String ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

To view the source code for android.provider Settings ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS.

Click Source Link

Document

Activity Action: Ask the user to allow an app to ignore battery optimizations (that is, put them on the whitelist of apps shown by #ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS ).

Usage

From source file:com.commonsware.android.antidoze.EventDemoActivity.java

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

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
        String pkg = getPackageName();
        PowerManager pm = getSystemService(PowerManager.class);

        if (!pm.isIgnoringBatteryOptimizations(pkg)) {
            Intent i = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
                    .setData(Uri.parse("package:" + pkg));

            startActivity(i);// ww w. j a  v  a  2s . com
        }
    }

    if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
        getSupportFragmentManager().beginTransaction().add(android.R.id.content, new EventLogFragment())
                .commit();
        startService(new Intent(this, ScheduledService.class));
    }
}

From source file:org.microg.tools.selfcheck.SystemChecks.java

@Override
public void tryResolve(Fragment fragment) {
    Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
    intent.setData(Uri.parse("package:" + fragment.getActivity().getPackageName()));
    fragment.startActivityForResult(intent, REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
}

From source file:com.easemob.helpdeskdemo.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(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);/*from w ww .j a v a  2  s  .co m*/
        }
    }

    setContentView(R.layout.em_activity_main);
    if (savedInstanceState != null) {
        currentTabIndex = savedInstanceState.getInt("selectedIndex", 0);
    }
    if (shopFragment != null) {
        shopFragment = getSupportFragmentManager().findFragmentByTag(shopFragment.getClass().getName());
        settingFragment = getSupportFragmentManager().findFragmentByTag(settingFragment.getClass().getName());
        ticketListFragment = getSupportFragmentManager()
                .findFragmentByTag(ticketListFragment.getClass().getName());
        fragments = new Fragment[] { shopFragment, ticketListFragment, settingFragment };
        getSupportFragmentManager().beginTransaction().hide(shopFragment).hide(settingFragment)
                .hide(ticketListFragment).show(fragments[currentTabIndex]).commit();

    } else {
        shopFragment = new ShopFragment();
        settingFragment = new SettingFragment();
        ticketListFragment = new TicketListFragment();
        fragments = new Fragment[] { shopFragment, ticketListFragment, settingFragment };
        // shopFragment?
        FragmentTransaction trx = getSupportFragmentManager().beginTransaction();
        trx.add(R.id.fragment_container, shopFragment, shopFragment.getClass().getName())
                .add(R.id.fragment_container, ticketListFragment, ticketListFragment.getClass().getName())
                .add(R.id.fragment_container, settingFragment, settingFragment.getClass().getName())
                .hide(settingFragment).hide(ticketListFragment).hide(shopFragment)
                .show(fragments[currentTabIndex]);
        trx.commit();
    }
    mBottomNav = $(R.id.bottom_navigation);
    mBottomNav.setBottomNavigationSelectedListener(this);
    //??listener
    connectionListener = new MyConnectionListener();
    ChatClient.getInstance().addConnectionListener(connectionListener);
    //6.0????target api?23demo??????
    requestPermissions();
}

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

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

    // ??????/*from   w w  w. j  ava 2 s.com*/
    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: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);//  www. j av  a  2 s. c  o  m
        }
    }
}

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

private void checkVersion() {
    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);/* w w w  .j  av a 2  s.  co  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 .co m*/
        }
    }
}

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);/*w w w.  j  a  v  a 2s . co m*/
    }
    startService(new Intent(this, TrackerService.class));
}

From source file:com.eveningoutpost.dexdrip.Home.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    mActivity = this;

    if (!xdrip.checkAppContext(getApplicationContext())) {
        toast("Unusual internal context problem - please report");
        Log.wtf(TAG, "xdrip.checkAppContext FAILED!");
        try {/*from   w w  w .j  a va 2 s.  c  o  m*/
            xdrip.initCrashlytics(getApplicationContext());
            Crashlytics.log("xdrip.checkAppContext FAILED!");
        } catch (Exception e) {
            // nothing we can do really
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // not much to do
        }
        if (!xdrip.checkAppContext(getApplicationContext())) {
            toast("Cannot start - please report context problem");
            finish();
        }
    }
    xdrip.checkForcedEnglish(Home.this);
    menu_name = getString(R.string.home_screen);

    super.onCreate(savedInstanceState);
    setTheme(R.style.AppThemeToolBarLite); // for toolbar mode

    set_is_follower();

    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    final boolean checkedeula = checkEula();

    //if (Build.VERSION.SDK_INT >= 21) {
    //    getWindow().setNavigationBarColor(Color.BLUE);
    //    getWindow().setStatusBarColor(getCol(X.color_home_chart_background));
    //}
    setContentView(R.layout.activity_home);

    Toolbar mToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(mToolbar);

    //findViewById(R.id.home_layout_holder).setBackgroundColor(getCol(X.color_home_chart_background));
    this.dexbridgeBattery = (TextView) findViewById(R.id.textBridgeBattery);
    this.parakeetBattery = (TextView) findViewById(R.id.parakeetbattery);
    this.sensorAge = (TextView) findViewById(R.id.libstatus);
    this.extraStatusLineText = (TextView) findViewById(R.id.extraStatusLine);
    this.currentBgValueText = (TextView) findViewById(R.id.currentBgValueRealTime);

    extraStatusLineText.setText("");
    dexbridgeBattery.setText("");
    parakeetBattery.setText("");
    sensorAge.setText("");

    if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        this.currentBgValueText.setTextSize(100);
    }
    this.notificationText = (TextView) findViewById(R.id.notices);
    if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        this.notificationText.setTextSize(40);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Intent intent = new Intent();
        String packageName = getPackageName();
        Log.d(TAG, "Maybe ignoring battery optimization");
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)
                && !prefs.getBoolean("requested_ignore_battery_optimizations_new", false)) {
            Log.d(TAG, "Requesting ignore battery optimization");
            // prefs.edit().putBoolean("requested_ignore_battery_optimizations", true).apply();
            intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);
            JoH.static_toast_long("Select YES for best performance!");
        }
    }

    // jamorham voice input et al
    this.voiceRecognitionText = (TextView) findViewById(R.id.treatmentTextView);
    this.textBloodGlucose = (TextView) findViewById(R.id.textBloodGlucose);
    this.textCarbohydrates = (TextView) findViewById(R.id.textCarbohydrate);
    this.textInsulinDose = (TextView) findViewById(R.id.textInsulinUnits);
    this.textTime = (TextView) findViewById(R.id.textTimeButton);
    this.btnBloodGlucose = (ImageButton) findViewById(R.id.bloodTestButton);
    this.btnCarbohydrates = (ImageButton) findViewById(R.id.buttonCarbs);
    this.btnInsulinDose = (ImageButton) findViewById(R.id.buttonInsulin);
    this.btnCancel = (ImageButton) findViewById(R.id.cancelTreatment);
    this.btnApprove = (ImageButton) findViewById(R.id.approveTreatment);
    this.btnTime = (ImageButton) findViewById(R.id.timeButton);
    this.btnUndo = (ImageButton) findViewById(R.id.btnUndo);
    this.btnRedo = (ImageButton) findViewById(R.id.btnRedo);
    this.btnVehicleMode = (ImageButton) findViewById(R.id.vehicleModeButton);

    hideAllTreatmentButtons();

    if (searchWords == null) {
        initializeSearchWords("");
    }

    this.btnSpeak = (ImageButton) findViewById(R.id.btnTreatment);
    btnSpeak.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            promptTextInput();

        }
    });
    btnSpeak.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            promptSpeechInput();
            return true;
        }
    });

    this.btnNote = (ImageButton) findViewById(R.id.btnNote);
    btnNote.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (Home.getPreferencesBooleanDefaultFalse("default_to_voice_notes")) {
                showNoteTextInputDialog(v, 0);
            } else {
                promptSpeechNoteInput(v);
            }
            return false;
        }
    });
    btnNote.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!Home.getPreferencesBooleanDefaultFalse("default_to_voice_notes")) {
                showNoteTextInputDialog(v, 0);
            } else {
                promptSpeechNoteInput(v);
            }
        }
    });

    btnCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            cancelTreatment();
        }
    });

    btnApprove.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            processAndApproveTreatment();
        }
    });

    btnInsulinDose.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // proccess and approve treatment
            textInsulinDose.setVisibility(View.INVISIBLE);
            btnInsulinDose.setVisibility(View.INVISIBLE);
            Treatments.create(0, thisinsulinnumber, Treatments.getTimeStampWithOffset(thistimeoffset));
            reset_viewport = true;
            if (hideTreatmentButtonsIfAllDone()) {
                updateCurrentBgInfo("insulin button");
            }
        }
    });
    btnCarbohydrates.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // proccess and approve treatment
            textCarbohydrates.setVisibility(View.INVISIBLE);
            btnCarbohydrates.setVisibility(View.INVISIBLE);
            reset_viewport = true;
            Treatments.create(thiscarbsnumber, 0, Treatments.getTimeStampWithOffset(thistimeoffset));
            if (hideTreatmentButtonsIfAllDone()) {
                updateCurrentBgInfo("carbs button");
            }
        }
    });

    btnBloodGlucose.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            reset_viewport = true;
            processCalibration();
        }
    });

    btnTime.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // clears time if clicked
            textTime.setVisibility(View.INVISIBLE);
            btnTime.setVisibility(View.INVISIBLE);
            if (hideTreatmentButtonsIfAllDone()) {
                updateCurrentBgInfo("time button");
            }
        }
    });

    final DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int screen_width = dm.widthPixels;
    int screen_height = dm.heightPixels;

    if (screen_width <= 320) {
        small_width = true;
        small_screen = true;
    }
    if (screen_height <= 320) {
        small_height = true;
        small_screen = true;
    }
    final int refdpi = 320;
    Log.d(TAG, "Width height: " + screen_width + " " + screen_height + " DPI:" + dm.densityDpi);

    JoH.fixActionBar(this);
    try {
        getSupportActionBar().setTitle(R.string.app_name);
    } catch (NullPointerException e) {
        Log.e(TAG, "Couldn't set title due to null pointer");
    }
    activityVisible = true;

    // handle incoming extras
    Bundle bundle = getIntent().getExtras();
    processIncomingBundle(bundle);

    checkBadSettings();

    // lower priority
    PlusSyncService.startSyncService(getApplicationContext(), "HomeOnCreate");
    ParakeetHelper.notifyOnNextCheckin(false);

    if ((checkedeula) && (!getString(R.string.app_name).equals("xDrip+"))) {
        showcasemenu(SHOWCASE_VARIANT);
    }

}

From source file:org.deviceconnect.android.manager.core.util.DConnectUtil.java

/**
 * Doze???./*from  w  ww  . j ava  2 s  .c o m*/
 * <p>
 * Doze???????????<br>
 * Android M ?? OS ????????????
 * </p>
 *
 * @param context 
 */
public static void startConfirmIgnoreDozeMode(final Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
        intent.setData(Uri.parse("package:" + context.getPackageName()));
        context.startActivity(intent);
    }
}