Make Call in Android Application using default call application

前端 未结 3 1669
无人及你
无人及你 2020-12-11 03:32

I am using following code to make a call from my android application:

Intent intent = new Intent(Intent.ACTION_CALL);                 
intent.setData(Uri.par         


        
3条回答
  •  醉梦人生
    2020-12-11 04:16

    find all app with dial ability

    fun getPackagesOfDialerApps(context: Context): List {
        val packageNames = ArrayList()
        // Declare action which target application listen to initiate phone call
        val intent = Intent()
        intent.action = Intent.ACTION_DIAL
        // Query for all those applications
        val resolveInfos = context.packageManager.queryIntentActivities(intent, 0)
        // Read package name of all those applications
        for (resolveInfo in resolveInfos) {
            val activityInfo = resolveInfo.activityInfo
            packageNames.add(activityInfo.applicationInfo.packageName)
        }
        return packageNames
    }
    

    call method

    val callIntent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:02188888888"))
    callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    context?.let {
        for(dialerApp in Utils.getPackagesOfDialerApps(it)){
            val appPackageName= dialerApp.toLowerCase(Locale.ENGLISH)
            if(appPackageName == "com.android.phone" ||
                appPackageName  == "com.android.server.telecom" ||
                appPackageName == "com.samsung.android.contacts"){
                callIntent.setPackage(appPackageName)
                break
            }
        }
    }
    try {
        startActivity(callIntent)
    } catch (ex: ActivityNotFoundException){
        callIntent.setPackage(null)
        startActivity(callIntent)
    }
    

提交回复
热议问题