1
votes

Le lancement d'un numéroteur à partir d'une application sous Android donne une erreur

J'essaie d'appeler un utilisateur à partir de mon application en lançant le numéroteur sous Android

J'ai fourni l'autorisation manifeste :

Exception: Method threw 'android.content.ActivityNotFoundException' exception.

Message: No Activity found to handle Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxx pkg=com.android.phone }

J'ai également fourni l'autorisation d'exécution

Code:

private fun startPhoneDial(phoneNo: String) {
        val callIntent = Intent(Intent.ACTION_CALL)
        //callIntent.data = Uri.parse(phoneNo)
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
            callIntent.setPackage("com.android.phone")
        }else{
            callIntent.setPackage("com.android.server.telecom")
        }
        callIntent.data = Uri.parse("tel:$phoneNo")
        startActivity(callIntent)
    }

Erreur- Stack-Trace :

<uses-permission android:name="android.permission.CALL_PHONE"/>


4 commentaires

L'erreur suggère qu'il n'y a pas d'application sur le téléphone avec le package com.android.phone qui peut gérer l'intention. Essayez de supprimer le package et créez également un sélecteur d'intention


L'exécutez-vous sur une tablette ou quelque chose sans application de téléphonie?


Même si je commente callIntent.setPackage ("com.android.phone") , j'obtiens toujours l'erreur


@SaurabhThorat ... je cours sur mon téléphone


5 Réponses :


3
votes

Essayez comme ceci.

val callIntent = Intent(Intent.ACTION_DIAL)
callIntent.setData(Uri.parse("tel:" + phone_number));


0 commentaires

1
votes

Utilisez cette fonction

fun callANumber(context: Context, phoneNo: String) {
     if (TextUtils.isEmpty(phoneNo)) {
        return
    }

    val callIntent = Intent(Intent.ACTION_CALL)
    callIntent.data = Uri.parse("tel:$phoneNo")
    
    try {
        context.startActivity(callIntent)
    } catch (e: ActivityNotFoundException) {
        Toast.makeText(context,"No Activity found which can handle intent",Toast.LENGTH_LONG).show()
    }

}


2 commentaires

CALL_PHONE n'est pas nécessaire pour ouvrir le numéroteur. Il n'est nécessaire que lorsque vous souhaitez appeler directement sans interaction de l'utilisateur.


@Borja ya, merci édité



1
votes

Je vous suggère de supprimer ce paquet codé en dur à la place, utilisez simplement l'intention générique pour ouvrir le numéroteur car cela appellera l'intention disponible au lieu de celle donnée.

Ou vous placez simplement ce code ci-dessous après avoir géré l'exception d'activité non trouvée.

private fun startPhoneDial(phoneNo: String) {
        val callIntent = Intent(Intent.ACTION_CALL)
        //callIntent.data = Uri.parse(phoneNo)
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
            callIntent.setPackage("com.android.phone")
        }else{
            callIntent.setPackage("com.android.server.telecom")
        }
        callIntent.data = Uri.parse("tel:$phoneNo")
        try{
        startActivity(callIntent)        
        }
        catch(exp : ActivityNotFoundException){
         val intent = new Intent(Intent.ACTION_DIAL);
         intent.setData(Uri.parse("tel:${phoneNo}"));
         startActivity(intent); 

        }
    }


0 commentaires

1
votes

Nous pouvons appeler directement ACTION_DIAL.

            val phone = "+919898989898"
            val intent = Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", phone, null))
            startActivity(intent)

référence: - https://stackoverflow.com / a / 18973484/2553615


0 commentaires

0
votes

Parce que c'est l'inverse ... Dans les versions plus petites que lollipop, c'est:

private fun startPhoneDial(phoneNo: String) {
    val callIntent = Intent(Intent.ACTION_CALL)
    //callIntent.data = Uri.parse(phoneNo)
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
        callIntent.setPackage("com.android.phone")
    }else{
        callIntent.setPackage("com.android.server.telecom")
    }
    callIntent.data = Uri.parse("tel:$phoneNo")
    startActivity(callIntent)
}

À partir des versions commençant à lollipop, c'est:

com.android.server.telecom

Vous devriez donc simplement échanger votre signe supérieur à comme:

com.android.phone


0 commentaires