কলগুলি নিরীক্ষণ করুন

Android 10 (API লেভেল ২৯) বা তার পরবর্তী যেকোনও ভার্সনে রান করা ডিভাইসে আপনার অ্যাপকে ব্যবহারকারীর অ্যাড্রেস বুকে নেই এমন নম্বর থেকে আসা কলকে সম্ভাব্য স্প্যাম কল হিসেবে শনাক্ত করার অনুমতি দেয়। ব্যবহারকারীরা স্প্যাম কল সাইলেন্টলি বাতিল করার বিকল্প বেছে নিতে পারেন। ব্যবহারকারী কল মিস করলে, তাকে আরও বেশি স্বচ্ছতা প্রদান করতে, এইসব ব্লক করা কল সম্পর্কে তথ্য কল লগে রেকর্ড করা হয়। Android 10 API ব্যবহার করলে, কল স্ক্রিনিং ও কলার আইডি ফাংশনালিটি প্রদান করার জন্য ব্যবহারকারীর থেকে 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.
                }
            }
        }
    }
}

জাভা

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
            }
        }
    }
}

নতুন কলে কীভাবে উত্তর দিতে হবে তা সিস্টেমকে জানাতে respondToCall() কল করতে onScreenCall() ফাংশন সেট করুন। এই ফাংশন একটি 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)

জাভা

// 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>