54 votes

faire un appel téléphonique cliquer sur un bouton

je suis un nouveau programmeur dans l'application android

j'ai créé un bouton dans mon application, quand j'ai cliqué sur un bouton alors je voudrais faire un appel. j'ai écrit le code comme suit

 ((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
  @Override
  public void onClick(View v) {
    String phno="10digits";

    Intent i=new Intent(Intent.ACTION_DIAL,Uri.parse(phno));
    startActivity(i);
  }
});
 

lorsque j'exécute cette application, elle affiche le bouton, lorsque je clique sur le bouton, je reçois une erreur de fermeture forcée.L'erreur s'affiche dans le journal de chat comme suit

 03-23 15:04:16.166: ERROR/AndroidRuntime(1021): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=9392438004 }
 

comment puis-je résoudre ce problème ...

Aidez-moi, s'il vous plaît

Merci d'avance

146voto

Shaista Naaz Points 1934

Avez-vous donné l'autorisation dans le fichier manifeste

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

et à l'intérieur de votre activité

   Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:123456789"));
    startActivity(callIntent);
 

Faites-moi savoir si vous rencontrez un problème.

16voto

Nepster Points 893

Il y a deux intentions d'appeler / commencer à appeler: ACTION_CALL et ACTION_DIAL.

ACTION_DIAL n'ouvrira le composeur qu'avec le numéro rempli, mais permet à l'utilisateur d'appeler ou de rejeter l'appel. ACTION_CALL appellera immédiatement le numéro et nécessite une autorisation supplémentaire.

Alors assurez-vous d'avoir la permission

uses-permission android: name = "android.permission.CALL_PHONE" dans votre AndroidManifest.xml

 <manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dbm.pkg"
    android:versionCode="1"
    android:versionName="1.0">

    <!-- NOTE! Your uses-permission must be outside the "application" tag
               but within the "manifest" tag. -->

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

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name">

        <!-- Insert your other stuff here -->

    </application>

    <uses-sdk android:minSdkVersion="9" />
</manifest> 
 

13voto

kenwen Points 58

Rien de ce qui précède n'a fonctionné donc avec un peu de bricolage voici le code qui a fait pour moi

         Intent i = new Intent(Intent.ACTION_DIAL);
        String p = "tel:" + getString(R.string.phone_number);
        i.setData(Uri.parse(p));
        startActivity(i);
 

12voto

Harshad Points 3188

changez votre chaîne en String phno="tel:10digits"; et réessayez.

4voto

Ashu Singh Points 166

ajoutez "tel:" avec votre numéro à composer selon votre intention, puis démarrez votre activité.

 Intent myIntent = new Intent(Intent.ACTION_CALL);
 String phNum = "tel:" + "1234567890";
 myIntent.setData(Uri.parse(phNum));
  startActivity( myIntent ) ;
 

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X