1

I am making an application to send msg and use a service, the problem is that the service on Android 9 stops because there is a rule that in energy saving force to stop the service.

What I thought is to ask the user to allow skip energy saving for the application.

I tried and couldn't, someone help me?

I'll send the code I have to try help :\

Xamarin.Android

Img Notification Starts Service:

notification

Manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.1" package="Sms.Sms" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="27" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
        <service android:name="com.xamarin.example.DemoService" android:directBootAware="true" android:permission="android.permission.BIND_JOB_SERVICE" />
    </application>
</manifest>

Codes\Manifest file\Img:

All Files :)

If it's a bad question say don't hate, I try

Gonçalo Garrido
  • 126
  • 2
  • 11

1 Answers1

1

You can't set the power saving mode programmatically.

It's bad practice to control the user's device settings from your app.

Rather consider suspending background services when battery levels are low.

Or to notify the user of low battery power and advising the user to switch of unnecessary settings like Bluetooth or WiFi.

the settings to turn off the power saving

Leo Zhu
  • 15,726
  • 1
  • 7
  • 23
  • Yes, what I I thought it was asking the user to disable power saving for a given application – Gonçalo Garrido Dec 13 '19 at 11:38
  • 1
    @GonçaloGarrido You can enable/disable Battery Saver programmatically on rooted devices,could refer to https://stackoverflow.com/a/31369841/10768653 – Leo Zhu Dec 16 '19 at 05:48