diff --git a/dialer/android/app/src/main/AndroidManifest.xml b/dialer/android/app/src/main/AndroidManifest.xml
index c2a9779..fa7ca1f 100644
--- a/dialer/android/app/src/main/AndroidManifest.xml
+++ b/dialer/android/app/src/main/AndroidManifest.xml
@@ -13,6 +13,7 @@
+
{
val phoneNumber = call.argument("phoneNumber")
if (phoneNumber != null) {
- val success = CallService.makeGsmCall(this, phoneNumber)
- if (success) {
+ try {
+ val intent = Intent(Intent.ACTION_CALL, Uri.parse("tel:$phoneNumber"))
+ startActivity(intent)
result.success(mapOf("status" to "calling", "phoneNumber" to phoneNumber))
- } else {
+ } catch (e: Exception) {
+ Log.e(TAG, "Failed to make GSM call: ${e.message}")
result.error("CALL_FAILED", "Failed to initiate call", null)
}
} else {
@@ -101,7 +103,7 @@ class MainActivity : FlutterActivity() {
}
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, KEYSTORE_CHANNEL)
- .setMethodCallHandler { call, result ->
+ .setMethodCallHandler { call, result ->
KeystoreHelper(call, result).handleMethodCall()
}
@@ -212,10 +214,13 @@ class MainActivity : FlutterActivity() {
intent?.let {
if (it.getBooleanExtra("isIncomingCall", false)) {
val phoneNumber = it.getStringExtra("phoneNumber")
- Log.d(TAG, "Received incoming call intent for $phoneNumber")
- MyInCallService.channel?.invokeMethod("incomingCallFromNotification", mapOf(
- "phoneNumber" to phoneNumber
- ))
+ val showScreen = it.getBooleanExtra("showIncomingCallScreen", false)
+ Log.d(TAG, "Received incoming call intent for $phoneNumber, showScreen=$showScreen")
+ if (showScreen) {
+ MyInCallService.channel?.invokeMethod("incomingCallFromNotification", mapOf(
+ "phoneNumber" to phoneNumber
+ ))
+ }
}
}
}
diff --git a/dialer/android/app/src/main/kotlin/com/icing/dialer/services/MyInCallService.kt b/dialer/android/app/src/main/kotlin/com/icing/dialer/services/MyInCallService.kt
index 24c922d..7657cba 100644
--- a/dialer/android/app/src/main/kotlin/com/icing/dialer/services/MyInCallService.kt
+++ b/dialer/android/app/src/main/kotlin/com/icing/dialer/services/MyInCallService.kt
@@ -39,7 +39,7 @@ class MyInCallService : InCallService() {
"state" to stateStr
))
if (state == Call.STATE_RINGING) {
- showIncomingCallNotification(call.details.handle.toString().replace("tel:", ""))
+ showIncomingCallScreen(call.details.handle.toString().replace("tel:", ""))
} else if (state == Call.STATE_DISCONNECTED || state == Call.STATE_DISCONNECTING) {
Log.d(TAG, "Call ended: ${call.details.handle}")
channel?.invokeMethod("callEnded", mapOf("callId" to call.details.handle.toString()))
@@ -64,7 +64,7 @@ class MyInCallService : InCallService() {
"state" to stateStr
))
if (stateStr == "ringing") {
- showIncomingCallNotification(call.details.handle.toString().replace("tel:", ""))
+ showIncomingCallScreen(call.details.handle.toString().replace("tel:", ""))
}
call.registerCallback(callCallback)
}
@@ -84,10 +84,19 @@ class MyInCallService : InCallService() {
channel?.invokeMethod("audioStateChanged", mapOf("route" to state.route))
}
- private fun showIncomingCallNotification(phoneNumber: String) {
- val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ private fun showIncomingCallScreen(phoneNumber: String) {
+ // Launch MainActivity with intent to show IncomingCallPage
+ val intent = Intent(this, MainActivity::class.java).apply {
+ flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
+ putExtra("phoneNumber", phoneNumber)
+ putExtra("isIncomingCall", true)
+ putExtra("showIncomingCallScreen", true) // New flag to signal immediate UI
+ }
+ startActivity(intent)
+ Log.d(TAG, "Launched MainActivity to show incoming call screen for $phoneNumber")
- // Create notification channel (Android 8.0+)
+ // Optional: Keep notification as a fallback
+ val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
NOTIFICATION_CHANNEL_ID,
@@ -101,20 +110,11 @@ class MyInCallService : InCallService() {
notificationManager.createNotificationChannel(channel)
}
- // Intent to open MainActivity with phone number
- val intent = Intent(this, MainActivity::class.java).apply {
- flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
- putExtra("phoneNumber", phoneNumber)
- putExtra("isIncomingCall", true)
- }
val pendingIntent = PendingIntent.getActivity(
- this,
- 0,
- intent,
+ this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0)
)
- // Build notification
val notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(android.R.drawable.ic_dialog_alert) // Replace with your app icon
.setContentTitle("Incoming Call")
@@ -122,7 +122,7 @@ class MyInCallService : InCallService() {
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
- .setOngoing(true) // Keep visible until call ends
+ .setOngoing(true)
.build()
notificationManager.notify(NOTIFICATION_ID, notification)
diff --git a/dialer/lib/services/call_service.dart b/dialer/lib/services/call_service.dart
index 5975210..99bd922 100644
--- a/dialer/lib/services/call_service.dart
+++ b/dialer/lib/services/call_service.dart
@@ -117,7 +117,7 @@ class CallService {
print('CallService: Making GSM call to $phoneNumber');
final result = await _channel.invokeMethod('makeGsmCall', {"phoneNumber": phoneNumber});
print('CallService: makeGsmCall result: $result');
- final resultMap = Map.from(result as Map); // Safe cast
+ final resultMap = Map.from(result as Map);
if (resultMap["status"] != "calling") {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Failed to initiate call")),
@@ -138,7 +138,7 @@ class CallService {
print('CallService: Hanging up call');
final result = await _channel.invokeMethod('hangUpCall');
print('CallService: hangUpCall result: $result');
- final resultMap = Map.from(result as Map); // Safe cast
+ final resultMap = Map.from(result as Map);
if (resultMap["status"] != "ended") {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Failed to end call")),