Search in sources :

Example 1 with ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

use of android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS in project android by nextcloud.

the class SyncedFoldersActivity method showBatteryOptimizationInfo.

private void showBatteryOptimizationInfo() {
    if (powerManagementService.isPowerSavingExclusionAvailable() || checkIfBatteryOptimizationEnabled()) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, R.style.Theme_ownCloud_Dialog).setTitle(getString(R.string.battery_optimization_title)).setMessage(getString(R.string.battery_optimization_message)).setPositiveButton(getString(R.string.battery_optimization_disable), (dialog, which) -> {
            // show instant upload
            @SuppressLint("BatteryLife") Intent intent = new Intent(ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:" + BuildConfig.APPLICATION_ID));
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            }
        }).setNeutralButton(getString(R.string.battery_optimization_close), (dialog, which) -> dialog.dismiss()).setIcon(R.drawable.ic_battery_alert);
        if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
            AlertDialog alertDialog = alertDialogBuilder.show();
            ThemeButtonUtils.themeBorderlessButton(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE), alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
        }
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) User(com.nextcloud.client.account.User) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) UNPERSISTED_ID(com.owncloud.android.datamodel.SyncedFolderDisplayItem.UNPERSISTED_ID) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) OCFile(com.owncloud.android.datamodel.OCFile) Clock(com.nextcloud.client.core.Clock) SyncedFolderDisplayItem(com.owncloud.android.datamodel.SyncedFolderDisplayItem) PowerManager(android.os.PowerManager) Locale(java.util.Locale) Map(java.util.Map) View(android.view.View) ThemeUtils(com.owncloud.android.utils.theme.ThemeUtils) BuildConfig(com.owncloud.android.BuildConfig) Log(android.util.Log) MediaFolder(com.owncloud.android.datamodel.MediaFolder) MediaFoldersDetectionWork(com.nextcloud.client.jobs.MediaFoldersDetectionWork) SyncedFoldersLayoutBinding(com.owncloud.android.databinding.SyncedFoldersLayoutBinding) NotificationManager(android.app.NotificationManager) AppPreferences(com.nextcloud.client.preferences.AppPreferences) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) List(java.util.List) NotificationWork(com.nextcloud.client.jobs.NotificationWork) MainApp(com.owncloud.android.MainApp) FileUploader(com.owncloud.android.files.services.FileUploader) SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) R(com.owncloud.android.R) ThemeButtonUtils(com.owncloud.android.utils.theme.ThemeButtonUtils) Context(android.content.Context) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) PermissionUtil(com.owncloud.android.utils.PermissionUtil) AlertDialog(androidx.appcompat.app.AlertDialog) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Intent(android.content.Intent) HashMap(java.util.HashMap) MediaFolderType(com.owncloud.android.datamodel.MediaFolderType) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Lifecycle(androidx.lifecycle.Lifecycle) SuppressLint(android.annotation.SuppressLint) SyncedFolderProvider(com.owncloud.android.datamodel.SyncedFolderProvider) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) PowerManagementService(com.nextcloud.client.device.PowerManagementService) SyncedFolderAdapter(com.owncloud.android.ui.adapter.SyncedFolderAdapter) SyncedFolderUtils(com.owncloud.android.utils.SyncedFolderUtils) MediaGridItemDecoration(com.owncloud.android.ui.decoration.MediaGridItemDecoration) MediaProvider(com.owncloud.android.datamodel.MediaProvider) SyncedFolderParcelable(com.owncloud.android.ui.dialog.parcel.SyncedFolderParcelable) FragmentManager(androidx.fragment.app.FragmentManager) NameCollisionPolicy(com.owncloud.android.files.services.NameCollisionPolicy) Optional(com.nextcloud.java.util.Optional) TextUtils(android.text.TextUtils) File(java.io.File) BackgroundJobManager(com.nextcloud.client.jobs.BackgroundJobManager) Injectable(com.nextcloud.client.di.Injectable) Activity(android.app.Activity) Collections(java.util.Collections) SyncedFolderPreferencesDialogFragment(com.owncloud.android.ui.dialog.SyncedFolderPreferencesDialogFragment) SuppressLint(android.annotation.SuppressLint) Intent(android.content.Intent)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 NotificationManager (android.app.NotificationManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 PowerManager (android.os.PowerManager)1 ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS (android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 NonNull (androidx.annotation.NonNull)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 DrawerLayout (androidx.drawerlayout.widget.DrawerLayout)1 FragmentManager (androidx.fragment.app.FragmentManager)1