@qusaieilouti99/call-manager 0.1.70 → 0.1.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,5 +18,8 @@
|
|
|
18
18
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
|
|
19
19
|
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
|
20
20
|
|
|
21
|
+
|
|
22
|
+
<!-- For knowing the activity state-->
|
|
23
|
+
<uses-permission android:name="android.permission.GET_TASKS" />
|
|
21
24
|
<!-- No components needed here - they're declared in app manifest -->
|
|
22
25
|
</manifest>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package com.margelo.nitro.qusaieilouti99.callmanager
|
|
2
2
|
|
|
3
|
+
import android.app.ActivityManager
|
|
3
4
|
import android.app.Activity
|
|
4
5
|
import android.app.Application
|
|
5
6
|
import android.app.Notification
|
|
@@ -996,7 +997,44 @@ object CallEngine {
|
|
|
996
997
|
startForegroundService() // Just restart the service with updated info
|
|
997
998
|
}
|
|
998
999
|
|
|
1000
|
+
private fun isMainActivityInForeground(): Boolean {
|
|
1001
|
+
val context = requireContext()
|
|
1002
|
+
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
1003
|
+
|
|
1004
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
1005
|
+
try {
|
|
1006
|
+
val tasks = activityManager.appTasks
|
|
1007
|
+
if (tasks.isNotEmpty()) {
|
|
1008
|
+
val taskInfo = tasks[0].taskInfo
|
|
1009
|
+
return taskInfo.topActivity?.className?.contains("MainActivity") == true
|
|
1010
|
+
}
|
|
1011
|
+
} catch (e: Exception) {
|
|
1012
|
+
Log.w(TAG, "Failed to get app tasks: ${e.message}")
|
|
1013
|
+
}
|
|
1014
|
+
} else {
|
|
1015
|
+
try {
|
|
1016
|
+
@Suppress("DEPRECATION")
|
|
1017
|
+
val tasks = activityManager.getRunningTasks(1)
|
|
1018
|
+
if (tasks.isNotEmpty()) {
|
|
1019
|
+
val runningTaskInfo = tasks[0]
|
|
1020
|
+
return runningTaskInfo.topActivity?.className?.contains("MainActivity") == true
|
|
1021
|
+
}
|
|
1022
|
+
} catch (e: Exception) {
|
|
1023
|
+
Log.w(TAG, "Failed to get running tasks: ${e.message}")
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
return false
|
|
1027
|
+
}
|
|
1028
|
+
|
|
999
1029
|
private fun bringAppToForeground() {
|
|
1030
|
+
// Check if MainActivity is already in foreground
|
|
1031
|
+
if (isMainActivityInForeground()) {
|
|
1032
|
+
Log.d(TAG, "MainActivity is already in foreground, skipping bringAppToForeground()")
|
|
1033
|
+
return
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
Log.d(TAG, "MainActivity is not in foreground, bringing to foreground")
|
|
1037
|
+
|
|
1000
1038
|
val context = requireContext()
|
|
1001
1039
|
val packageName = context.packageName
|
|
1002
1040
|
val launchIntent = context.packageManager.getLaunchIntentForPackage(packageName)
|