Android Telecom फ़्रेमवर्क, Android डिवाइस पर ऑडियो और वीडियो कॉल को मैनेज करता है. इसे "Telecom" भी कहा जाता है. इसमें सिम कार्ड पर काम करने वाले कॉल शामिल हैं. जैसे, टेलीफ़ोन फ़्रेमवर्क का इस्तेमाल करने वाले कॉल और Core-Telecom
Jetpack लाइब्रेरी का इस्तेमाल करने वाले वीओआईपी कॉल.
Telecom, ConnectionService
और
InCallService
जैसे मुख्य कॉम्पोनेंट को मैनेज करता है.
ConnectionService
को लागू करने के लिए, पीएसटीएन जैसी टेक्नोलॉजी का इस्तेमाल किया जाता है, ताकि कॉल को दूसरे पक्षों से कनेक्ट किया जा सके. फ़ोन पर ConnectionService
लागू करने का सबसे आम तरीका, टेलीफ़ोनी ConnectionService
है. इससे मोबाइल और इंटरनेट सेवा देने वाली कंपनी के नेटवर्क का इस्तेमाल करके, कॉल किए जाते हैं.
InCallService
लागू करने पर, टेलीकॉम कंपनी के मैनेज किए जाने वाले कॉल के लिए यूज़र इंटरफ़ेस मिलता है. साथ ही, उपयोगकर्ता को इन कॉल को कंट्रोल करने और उनसे इंटरैक्ट करने की सुविधा मिलती है. InCallService
को लागू करने का सबसे सामान्य तरीका, डिवाइस के साथ बंडल किया गया फ़ोन ऐप्लिकेशन है.
टेलीकॉम, स्विचबोर्ड के तौर पर काम करता है. यह उन कॉल को रूट करता है जिन्हें ConnectionService
इंप्लिकेशन, कॉल करने वाले उन यूज़र इंटरफ़ेस पर भेजते हैं जिन्हें InCallService
इंप्लिकेशन उपलब्ध कराते हैं.
Telecom APIs को इन वजहों से लागू किया जा सकता है:
- सिस्टम के फ़ोन ऐप्लिकेशन के लिए, कोई दूसरा ऐप्लिकेशन बनाने के लिए.
- Android की कॉलिंग सुविधा में कॉल करने का कोई समाधान इंटिग्रेट करने के लिए.
फ़ोन ऐप्लिकेशन को बदलना
Android डिवाइस पर डिफ़ॉल्ट फ़ोन ऐप्लिकेशन को बदलने के लिए,
InCallService
API लागू करें. आपके लागू किए गए तरीके को इन ज़रूरी शर्तों को पूरा करना होगा:
- इसमें कॉल करने की सुविधा नहीं होनी चाहिए. साथ ही, इसमें सिर्फ़ कॉल करने के लिए यूज़र इंटरफ़ेस होना चाहिए.
- यह उन सभी कॉल को मैनेज करना चाहिए जिनके बारे में दूरसंचार फ़्रेमवर्क को पता है. साथ ही, कॉल के टाइप के बारे में कोई अनुमान नहीं लगाना चाहिए. उदाहरण के लिए, यह नहीं माना जाना चाहिए कि कॉल, सिम पर आधारित टेलीफ़ोन कॉल हैं. साथ ही, कॉल पर ऐसी पाबंदियां भी नहीं लगानी चाहिए जो किसी एक
ConnectionService
पर आधारित हों. जैसे, वीडियो कॉल के लिए टेलीफ़ोन सेवा पर लगी पाबंदियां लागू करना.
ज़्यादा जानकारी के लिए, InCallService
देखें.
कॉल करने की सुविधा को इंटिग्रेट करना
Android में कॉलिंग सलूशन को इंटिग्रेट करने के लिए, आपके पास ये विकल्प हैं:
खुद मैनेज की जाने वाली Core-Telecom Jetpack लाइब्रेरी को लागू करना: यह विकल्प, कॉल करने की सुविधा देने वाले स्टैंडअलोन ऐप्लिकेशन के डेवलपर के लिए सबसे सही है. वे ऐसे डेवलपर होते हैं जो अपने कॉल को डिफ़ॉल्ट फ़ोन ऐप्लिकेशन में नहीं दिखाना चाहते. साथ ही, वे अपने यूज़र इंटरफ़ेस में अन्य कॉल भी नहीं दिखाना चाहते.
Core-Telecom
Jetpack लाइब्रेरी के साथ इंटिग्रेट करने पर, आपके ऐप्लिकेशन को डिवाइस पर सिस्टम टेलीफ़ोनी कॉलिंग के साथ-साथ, टेलीकॉम के साथ इंटिग्रेट किए गए अन्य स्टैंडअलोन कॉलिंग ऐप्लिकेशन के साथ भी इंटरऑपरेट करने में मदद मिलती है.Core-Telecom
लाइब्रेरी, ऑडियो रूटिंग और फ़ोकस को भी मैनेज करती है. ज़्यादा जानकारी के लिए, कॉल करने की सुविधा देने वाला ऐप्लिकेशन बनाना लेख पढ़ें.मैनेज किए जा रहे ConnectionService API को लागू करना: इस विकल्प की मदद से, कॉल के लिए यूज़र इंटरफ़ेस देने वाले डिवाइस के मौजूदा फ़ोन ऐप्लिकेशन पर आधारित कॉलिंग सलूशन को डेवलप किया जा सकता है. उदाहरण के लिए, तीसरे पक्ष की SIP कॉलिंग और वीओआईपी कॉलिंग सेवाएं. ज़्यादा जानकारी के लिए,
getDefaultDialerPackage()
देखें.सिर्फ़
ConnectionService
की मदद से, कॉल को कनेक्ट करने का तरीका बताया जाता है. इसका कोई यूज़र इंटरफ़ेस नहीं है.InCallService और ConnectionService API, दोनों को लागू करना: अगर आपको
ConnectionService
पर आधारित कॉलिंग सलूशन बनाना है, तो यह विकल्प सबसे सही है. इसमें आपको अपने हिसाब से यूज़र इंटरफ़ेस बनाना होगा. साथ ही, Android के सभी अन्य कॉल को भी उसी यूज़र इंटरफ़ेस में दिखाना होगा. इस तरीके का इस्तेमाल करते समय,InCallService
को लागू करने के लिए, कॉल के सोर्स के बारे में कोई अनुमान नहीं लगाया जाना चाहिए. साथ ही,ConnectionService
को लागू करने के बाद, डिफ़ॉल्ट फ़ोन ऐप्लिकेशन को अपने पसंदीदाInCallService
पर सेट किए बिना भी, यह सुविधा काम करती रहनी चाहिए.
कॉल स्क्रीन करें
Android 10 (एपीआई लेवल 29) या उसके बाद के वर्शन वाले डिवाइसों पर, आपके ऐप्लिकेशन को उन नंबरों से आने वाले कॉल की पहचान करने की अनुमति मिलती है जो उपयोगकर्ता की पता पुस्तिका में मौजूद नहीं हैं. ये कॉल संभावित स्पैम कॉल हो सकते हैं. उपयोगकर्ता, स्पैम कॉल को चुपचाप अस्वीकार करने का विकल्प चुन सकते हैं. जब उपयोगकर्ताओं को कॉल नहीं मिलते, तो उन्हें ज़्यादा पारदर्शिता देने के लिए, ब्लॉक किए गए इन कॉल की जानकारी कॉल लॉग में लॉग की जाती है. Android 10 एपीआई का इस्तेमाल करने पर, कॉल की स्क्रीनिंग और कॉलर आईडी की सुविधा देने के लिए, उपयोगकर्ता से READ_CALL_LOG
की अनुमति लेने की ज़रूरत नहीं होती.
कॉल की स्क्रीनिंग करने के लिए, CallScreeningService
के लागू होने का इस्तेमाल किया जाता है. जब कोई नया इनकमिंग या आउटगोइंग कॉल आता है और वह नंबर उपयोगकर्ता की संपर्क सूची में नहीं होता, तो onScreenCall()
फ़ंक्शन को कॉल करें. कॉल के बारे में जानकारी पाने के लिए,
Call.Details
ऑब्जेक्ट देखें. खास तौर पर, getCallerNumberVerificationStatus()
फ़ंक्शन में, नेटवर्क सेवा देने वाली कंपनी से मिले दूसरे नंबर की जानकारी शामिल होती है.
अगर पुष्टि नहीं हो पाती है, तो इसका मतलब है कि कॉल किसी अमान्य नंबर से आया है या यह स्पैम कॉल हो सकता है.
Kotlin
class ScreeningService : CallScreeningService() { // This function is called when an ingoing or outgoing call // is from a number not in the user's contacts list override fun onScreenCall(callDetails: Call.Details) { // Can check the direction of the call val isIncoming = callDetails.callDirection == Call.Details.DIRECTION_INCOMING if (isIncoming) { // the handle (e.g. phone number) that the Call is currently connected to val handle: Uri = callDetails.handle // determine if you want to allow or reject the call when (callDetails.callerNumberVerificationStatus) { Connection.VERIFICATION_STATUS_FAILED -> { // Network verification failed, likely an invalid/spam call. } Connection.VERIFICATION_STATUS_PASSED -> { // Network verification passed, likely a valid call. } else -> { // Network could not perform verification. // This branch matches Connection.VERIFICATION_STATUS_NOT_VERIFIED. } } } } }
Java
class ScreeningService extends CallScreeningService { @Override public void onScreenCall(@NonNull Call.Details callDetails) { boolean isIncoming = callDetails.getCallDirection() == Call.Details.DIRECTION_INCOMING; if (isIncoming) { Uri handle = callDetails.getHandle(); switch (callDetails.getCallerNumberVerificationStatus()) { case Connection.VERIFICATION_STATUS_FAILED: // Network verification failed, likely an invalid/spam call. break; case Connection.VERIFICATION_STATUS_PASSED: // Network verification passed, likely a valid call. break; default: // Network could not perform verification. // This branch matches Connection.VERIFICATION_STATUS_NOT_VERIFIED } } } }
onScreenCall()
फ़ंक्शन को कॉल करने के लिए सेट करें
respondToCall()
ताकि सिस्टम को नए कॉल का जवाब देने का तरीका बताया जा सके. यह फ़ंक्शन एक CallResponse
पैरामीटर लेता है. इसका इस्तेमाल करके, सिस्टम को कॉल को ब्लॉक करने, उपयोगकर्ता की तरह उसे अस्वीकार करने या उसे साइलेंट करने के लिए कहा जा सकता है. आपके पास यह भी कहने का विकल्प है कि इस कॉल को डिवाइस के कॉल लॉग में न जोड़ा जाए.
Kotlin
// Tell the system how to respond to the incoming call // and if it should notify the user of the call. val response = CallResponse.Builder() // Sets whether the incoming call should be blocked. .setDisallowCall(false) // Sets whether the incoming call should be rejected as if the user did so manually. .setRejectCall(false) // Sets whether ringing should be silenced for the incoming call. .setSilenceCall(false) // Sets whether the incoming call should not be displayed in the call log. .setSkipCallLog(false) // Sets whether a missed call notification should not be shown for the incoming call. .setSkipNotification(false) .build() // Call this function to provide your screening response. respondToCall(callDetails, response)
Java
// Tell the system how to respond to the incoming call // and if it should notify the user of the call. CallResponse.Builder response = new CallResponse.Builder(); // Sets whether the incoming call should be blocked. response.setDisallowCall(false); // Sets whether the incoming call should be rejected as if the user did so manually. response.setRejectCall(false); // Sets whether ringing should be silenced for the incoming call. response.setSilenceCall(false); // Sets whether the incoming call should not be displayed in the call log. response.setSkipCallLog(false); // Sets whether a missed call notification should not be shown for the incoming call. response.setSkipNotification(false); // Call this function to provide your screening response. respondToCall(callDetails, response.build());
आपको मेनिफ़ेस्ट फ़ाइल में, CallScreeningService
को लागू करने के लिए सही इंटेंट फ़िल्टर और अनुमति के साथ रजिस्टर करना होगा, ताकि सिस्टम इसे सही तरीके से ट्रिगर कर सके.
<service
android:name=".ScreeningService"
android:permission="android.permission.BIND_SCREENING_SERVICE">
<intent-filter>
<action android:name="android.telecom.CallScreeningService" />
</intent-filter>
</service>
कॉल को रीडायरेक्ट करना
Android 10 या इसके बाद के वर्शन वाले डिवाइस, कॉल इंटेंट को Android 9 या उससे पहले के वर्शन वाले डिवाइसों से अलग तरीके से मैनेज करते हैं. Android 10 और इसके बाद के वर्शन पर, ACTION_NEW_OUTGOING_CALL
ब्रॉडकास्ट की सुविधा काम नहीं करती. इसे CallRedirectionService
एपीआई से बदल दिया गया है. CallRedirectionService
, इंटरफ़ेस उपलब्ध कराता है, ताकि Android प्लैटफ़ॉर्म से किए गए आउटगोइंग कॉल में बदलाव किया जा सके. उदाहरण के लिए, तीसरे पक्ष के ऐप्लिकेशन, कॉल रद्द कर सकते हैं और उन्हें VoIP पर फिर से रूट कर सकते हैं.
Kotlin
class RedirectionService : CallRedirectionService() { override fun onPlaceCall( handle: Uri, initialPhoneAccount: PhoneAccountHandle, allowInteractiveResponse: Boolean ) { // Determine if the call should proceed, be redirected, or cancelled. val callShouldProceed = true val callShouldRedirect = false when { callShouldProceed -> { placeCallUnmodified() } callShouldRedirect -> { // Update the URI to point to a different phone number or modify the // PhoneAccountHandle and redirect. redirectCall(handle, initialPhoneAccount, true) } else -> { cancelCall() } } } }
Java
class RedirectionService extends CallRedirectionService { @Override public void onPlaceCall( @NonNull Uri handle, @NonNull PhoneAccountHandle initialPhoneAccount, boolean allowInteractiveResponse ) { // Determine if the call should proceed, be redirected, or cancelled. // Your app should implement this logic to determine the redirection. boolean callShouldProceed = true; boolean callShouldRedirect = false; if (callShouldProceed) { placeCallUnmodified(); } else if (callShouldRedirect) { // Update the URI to point to a different phone number or modify the // PhoneAccountHandle and redirect. redirectCall(handle, initialPhoneAccount, true); } else { cancelCall(); } } }
आपको इस सेवा को मेनिफ़ेस्ट में रजिस्टर करना होगा, ताकि सिस्टम इसे सही तरीके से शुरू कर सके.
<service
android:name=".RedirectionService"
android:permission="android.permission.BIND_CALL_REDIRECTION_SERVICE">
<intent-filter>
<action android:name="android.telecom.CallRedirectionService"/>
</intent-filter>
</service>
रीडायरेक्शन सेवा का इस्तेमाल करने के लिए, आपके ऐप्लिकेशन को RoleManager
से कॉल रीडायरेक्शन की भूमिका का अनुरोध करना होगा. इससे उपयोगकर्ता से पूछा जाएगा कि क्या उसे आपके ऐप्लिकेशन को कॉल रीडायरेक्ट करने की अनुमति देनी है. अगर आपके ऐप्लिकेशन को यह भूमिका नहीं दी गई है, तो आपकी रीडायरेक्ट सेवा का इस्तेमाल नहीं किया जाएगा.
आपको यह देखना चाहिए कि उपयोगकर्ता आपका ऐप्लिकेशन लॉन्च करने पर, आपके ऐप्लिकेशन में यह भूमिका है या नहीं, ताकि आप ज़रूरत के हिसाब से इसका अनुरोध कर सकें. RoleManager
से बनाए गए इंटेंट को लॉन्च किया जाता है. इसलिए, उपयोगकर्ता के चुने गए विकल्प को मैनेज करने के लिए, पक्का करें कि आपने onActivityResult()
फ़ंक्शन को बदल दिया हो.
Kotlin
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Tell the system that you want your app to handle call redirects. This // is done by using the RoleManager to register your app to handle redirects. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { val roleManager = getSystemService(Context.ROLE_SERVICE) as RoleManager // Check if the app needs to register call redirection role. val shouldRequestRole = roleManager.isRoleAvailable(RoleManager.ROLE_CALL_REDIRECTION) && !roleManager.isRoleHeld(RoleManager.ROLE_CALL_REDIRECTION) if (shouldRequestRole) { val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_REDIRECTION) startActivityForResult(intent, REDIRECT_ROLE_REQUEST_CODE) } } } companion object { private const val REDIRECT_ROLE_REQUEST_CODE = 1 } }
Java
class MainActivity extends AppCompatActivity { private static final int REDIRECT_ROLE_REQUEST_CODE = 0; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Tell the system that you want your app to handle call redirects. This // is done by using the RoleManager to register your app to handle redirects. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { RoleManager roleManager = (RoleManager) getSystemService(Context.ROLE_SERVICE); // Check if the app needs to register call redirection role. boolean shouldRequestRole = roleManager.isRoleAvailable(RoleManager.ROLE_CALL_REDIRECTION) && !roleManager.isRoleHeld(RoleManager.ROLE_CALL_REDIRECTION); if (shouldRequestRole) { Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_REDIRECTION); startActivityForResult(intent, REDIRECT_ROLE_REQUEST_CODE); } } } }