IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants graphiques Android Discussion :

problème avec le lien tel dans un webview


Sujet :

Composants graphiques Android

  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2013
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2013
    Messages : 100
    Points : 110
    Points
    110
    Par défaut problème avec le lien tel dans un webview
    Bonsoir, j'ai mon lien
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <a href="tel:000000000">Call</a>
    qui fonctionne bien dans mon site lancé sur mon téléphone androïde, mais lorsque le même site est incorporé dans un WebView, le lien ne fonctionne plus. il cherche plutôt a ouvrir une page. comment résoudre ce problème en java? merci

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2012
    Messages
    474
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2012
    Messages : 474
    Points : 586
    Points
    586
    Par défaut
    Bonjour,

    Déjà, inutile de créer un nouveau post si tu as fait une erreur, il y a la possibilité de modifier les post existant que tu crées.

    Pour ton problème, c'est normal si à aucun moment tu lui dit d'interpréter le lien comme numéro de téléphone. Et en android, interpréter un numéro signifie aussi de lancer l'application Téléphone.

    Tu trouveras un tuto complet ici, je ne l'ai pas vérifié mais ca ressemble à toutes les autres solutions que j'ai vue : https://android--code.blogspot.fr/20...n-webview.html

  3. #3
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2013
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2013
    Messages : 100
    Points : 110
    Points
    110
    Par défaut
    merci pour ta prompte réaction, je vais regarder et a tout a l'heure

  4. #4
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2013
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2013
    Messages : 100
    Points : 110
    Points
    110
    Par défaut
    merci pour le lien, mon code fonctionne bien
    voici le code pour ceux qui auront besoin que j'ai retouché
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    package com.cfsuman.me.androidcodesnippets;
     
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Build;
    import android.os.Bundle;
    import android.webkit.WebResourceRequest;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.Toast;
     
     
    public class MainActivity extends AppCompatActivity {
        private Context mContext;
        private Activity mActivity;
     
        private WebView mWebView;
     
     
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
     
            // Get the application context
            mContext = getApplicationContext();
            mActivity = MainActivity.this;
     
            // Get the widget reference from xml layout
            mWebView = findViewById(R.id.web_view);
     
     
            // Set the web view client
            mWebView.setWebViewClient(new WebViewClient(){
     
                // For api level bellow 24
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url){
                    Toast.makeText(mContext, "Old Method",Toast.LENGTH_SHORT).show();
     
                    if(url.startsWith("http")){
                        Toast.makeText(mContext,"Page link",Toast.LENGTH_SHORT).show();
                        // Return false means, web view will handle the link
                        return false;
                    }else if(url.startsWith("tel:")){
                        // Handle the tel: link
                        handleTelLink(url);
     
                        // Return true means, leave the current web view and handle the url itself
                        return true;
                    }
     
                    return false;
                }
     
     
                // From api level 24
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request){
                    Toast.makeText(mContext, "New Method",Toast.LENGTH_SHORT).show();
     
                    // Get the tel: url
                    String url = request.getUrl().toString();
     
                    if(url.startsWith("http")){
                        Toast.makeText(mContext,"Page link",Toast.LENGTH_SHORT).show();
                        // Return false means, web view will handle the link
                        return false;
                    }else if(url.startsWith("tel:")){
                        // Handle the tel: link
                        handleTelLink(url);
     
                        // Return true means, leave the current web view and handle the url itself
                        return true;
                    }
     
                    return false;
                }
            });
     
            // Load the url into web view
            //mWebView.loadUrl("https://paulund.co.uk/add-telephone-number-links-with-html5");
            mWebView.loadUrl("https://developers.google.com/web/fundamentals/native-hardware/click-to-call/");
        }
     
     
        // Custom method to handle html tel: link
        protected void handleTelLink(String url){
            // Initialize an intent to open dialer app with specified phone number
            // It open the dialer app and allow user to call the number manually
            Intent intent = new Intent(Intent.ACTION_DIAL);
     
            // Send phone number to intent as data
            intent.setData(Uri.parse(url));
     
            // Start the dialer app activity with number
            startActivity(intent);
        }
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 5
    Dernier message: 06/01/2009, 14h52
  2. problème avec la méthode getElementById() dans Firefox
    Par matrouba dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 19/12/2005, 08h55
  3. Problème avec le type BLOB dans oracle
    Par pguedia dans le forum Oracle
    Réponses: 1
    Dernier message: 10/11/2005, 17h33
  4. probléme avec une date/string dans un CommandText
    Par critok dans le forum Bases de données
    Réponses: 5
    Dernier message: 09/02/2005, 15h30
  5. problème avec masque de saisie dans table
    Par porki dans le forum Access
    Réponses: 6
    Dernier message: 13/10/2004, 08h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo