'How to accept and reject Incoming call using customized buttons in android 10?
I'm using ConnectionServices
but am unable to get how to accept and reject buttons work.
Here am trying ITelephony
services but as it is deprecated in API level 29
it doesn't work. Suggest to me any good technique or example of call accept and reject function that works in android 10.
Here is my customized activity code
class CallReceiver : AppCompatActivity() {
private lateinit var binding: CustomScreenBinding
@SuppressLint("Recycle")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = CustomScreenBinding.inflate(layoutInflater)
setContentView(binding.root)
keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
val telephony = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
val contactName = intent.getStringExtra("u_name")
Log.i("name", "name" + contactName)
binding.name.text = contactName
val contactNumber = intent.getStringExtra("u_number")
Log.i("number", "number" + contactNumber)
binding.number.text = contactNumber
val intent = intent
val id = intent.getLongExtra("u_id", 0)
Log.i("data", id.toString())
val contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id)
val displayPhotoUri =
Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO)
try {
val fd = contentResolver.openAssetFileDescriptor(displayPhotoUri, "r")
val buf = fd?.createInputStream()
val my_btmp = BitmapFactory.decodeStream(buf)
binding.photo.setImageBitmap(my_btmp)
} catch (e: IOException) {
}
val telephonyService: ITelephony
val tm = getSystemService(TELEPHONY_SERVICE)
val c = Class.forName(tm.javaClass.name)
val m = c.getDeclaredMethod("getITelephony")
m.isAccessible = true
telephonyService = m.invoke(tm) as ITelephony
val bundle = intent.extras
val phoneNumber = bundle!!.getString("incoming_number")
Log.d("INCOMING", phoneNumber!!)
binding.buttonHangup.setOnClickListener {
telephonyService.endCall()
Log.d("HANG UP", phoneNumber)
}
binding.buttonAnswer.setOnClickListener {
telephonyService.answerRingingCall()
}
}
}
Solution 1:[1]
android is imposing restrictions on what an App can do and cannot. meaning by that you don't have the entire control over the call management, and i think that's why you are unable to get how to accept and reject buttons.
I think the only solution for that is to build your own call app which will give you entire control over the call management.
follow this documentation: https://developer.android.com/guide/topics/connectivity/telecom/selfManaged
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mado |