Skip to content

Commit 8a19cc4

Browse files
2 parents 8d8b3cb + c9cf029 commit 8a19cc4

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

scripts/setupBatteryOptimization.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,44 +78,39 @@ class BatteryOptimizationHelper(reactContext: ReactApplicationContext) : ReactCo
7878
val context: Context = reactApplicationContext
7979
val packageName = context.packageName
8080
81-
Log.d("BatteryOptimizationHelper", "Opening battery optimization settings for " + packageName)
82-
83-
// First, try opening the specific battery optimization settings
84-
val intent = Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)
85-
intent.data = Uri.parse("package:" + packageName)
81+
// Try to open the specific screen to request ignore battery optimizations for this app
82+
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
83+
intent.data = Uri.parse("package:$packageName")
8684
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
8785
8886
if (intent.resolveActivity(context.packageManager) != null) {
8987
context.startActivity(intent)
90-
Log.d("BatteryOptimizationHelper", "Battery optimization settings opened!")
88+
Log.d("BatteryOptimizationHelper", "Requested ignore battery optimizations for $packageName")
9189
} else {
92-
// If direct setting fails, open general battery settings instead
93-
Log.e("BatteryOptimizationHelper", "Could not resolve activity for battery optimization settings! Trying general battery settings...")
94-
val generalIntent = Intent(Settings.ACTION_BATTERY_SAVER_SETTINGS)
90+
// Fallback: open the general battery optimization settings
91+
val generalIntent = Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)
9592
generalIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
96-
9793
if (generalIntent.resolveActivity(context.packageManager) != null) {
9894
context.startActivity(generalIntent)
99-
Log.d("BatteryOptimizationHelper", "General battery settings opened!")
95+
Log.d("BatteryOptimizationHelper", "Opened general battery optimization settings")
10096
} else {
101-
Log.e("BatteryOptimizationHelper", "Could not resolve activity for general battery settings!")
97+
Log.e("BatteryOptimizationHelper", "Could not resolve activity for battery optimization settings!")
10298
}
10399
}
104100
} catch (e: Exception) {
105101
Log.e("BatteryOptimizationHelper", "Error opening battery settings: " + e.message, e)
106102
}
107103
}
108-
}
109104
110-
class BatteryOptimizationPackage : ReactPackage {
111-
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
112-
return listOf(BatteryOptimizationHelper(reactContext))
113-
}
105+
class BatteryOptimizationPackage : ReactPackage {
106+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
107+
return listOf(BatteryOptimizationHelper(reactContext))
108+
}
114109
115-
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
116-
return emptyList()
110+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
111+
return emptyList()
112+
}
117113
}
118-
}
119114
`;
120115

121116
const createBatteryOptimizationHelper = async () => {

version.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.50",
3-
"iosBuildNumber": "50",
4-
"androidVersionCode": 50
2+
"version": "1.0.52",
3+
"iosBuildNumber": "52",
4+
"androidVersionCode": 52
55
}

0 commit comments

Comments
 (0)