Return to SIP service SIP service
1: package com.voipplus.mmsclient.Sip;
2:
3: import android.app.Service;
4: import android.content.;
5: import android.os.Binder;
6: import android.os.IBinder;
7:
8: public class SipService extends Service {
9: private static final String TAG = "SipService";
10:
11: private final IBinder binder = new LocalBinder();
12: private SipState sipState = SipState.IDLE;
13:
14: private String sipServerUrl;
15: private String sipUsername;
16: private String sipPassword;
17:
18: @Override
19: public void onCreate() {
20: super.onCreate();
21: SipUtils.debugInfo(TAG, "🟢 SIP Service Created", sipState);
22: }
23:
24: @Override
25: public IBinder onBind( intent) {
26: SipUtils.debugInfo(TAG, "🔗 SIP Service Bound", sipState);
27: return binder;
28: }
29:
30: // ✅ Binder class for accessing the service
31: public class LocalBinder extends Binder {
32: public SipService getService() {
33: return SipService.this;
34: }
35: }
36:
37: // ✅ Set SIP Server parameters
38: public void setSipServerParams(String serverUrl, String username, String password) {
39: this.sipServerUrl = serverUrl;
40: this.sipUsername = username;
41: this.sipPassword = password;
42: SipUtils.debugInfo(TAG, "🔗 SIP Server Params Set: " + serverUrl, sipState);
43: }
44:
45: // ✅ Register SIP Account
46: public void registerSipAccount() {
47: if (sipServerUrl == null || sipUsername == null || sipPassword == null) {
48: SipUtils.debugInfo(TAG, "❌ SIP Registration Failed: Missing credentials", sipState);
49: return;
50: }
51:
52: sipState = SipState.REGISTERING;
53: SipUtils.debugInfo(TAG, "🔄 Registering with SIP Server: " + sipServerUrl, sipState);
54:
55: // Simulating successful registration
56: new Thread(() -> {
57: try {
58: Thread.sleep(1000); // Simulated network delay
59: sipState = SipState.REGISTERED;
60: SipUtils.debugInfo(TAG, "✅ SIP Registered Successfully", sipState);
61: } catch (InterruptedException e) {
62: sipState = SipState.ERROR;
63: SipUtils.debugInfo(TAG, "❌ SIP Registration Error", sipState);
64: }
65: }).start();
66: }
67:
68: // ✅ Start a SIP Call
69: public void startSipCall(String callee) {
70: if (sipState != SipState.REGISTERED) {
71: SipUtils.debugInfo(TAG, "❌ Cannot start call: Not registered", sipState);
72: return;
73: }
74:
75: sipState = SipState.CALLING;
76: SipUtils.debugInfo(TAG, "📞 Calling: " + callee, sipState);
77:
78: // Simulating a call being established
79: new Thread(() -> {
80: try {
81: Thread.sleep(2000); // Simulated network delay
82: sipState = SipState.IN_CALL;
83: SipUtils.debugInfo(TAG, "✅ Call Established with " + callee, sipState);
84: } catch (InterruptedException e) {
85: sipState = SipState.ERROR;
86: SipUtils.debugInfo(TAG, "❌ Call Failed", sipState);
87: }
88: }).start();
89: }
90:
91: // ✅ End SIP Call
92: public void endSipCall() {
93: if (sipState != SipState.IN_CALL) {
94: SipUtils.debugInfo(TAG, "❌ No Active Call to End", sipState);
95: return;
96: }
97:
98: sipState = SipState.IDLE;
99: SipUtils.debugInfo(TAG, "🔴 Call Ended", sipState);
100: }
101:
102: // ✅ Get Current SIP State
103: public SipState getSipState() {
104: return sipState;
105: }
106:
107: @Override
108: public void onDestroy() {
109: super.onDestroy();
110: sipState = SipState.IDLE;
111: SipUtils.debugInfo(TAG, "🔴 SIP Service Destroyed", sipState);
112: }
113: }
114:
Return to SIP service
AndroidMosaic context:
Comments (
)
)
Link to this page:
http://www.vb-net.com/AndroidMosaic/Index20.htm
|
|