Bonjour,

Alors dans mon projet j'ai besoin d'aller sur une page internet afin de consulter des information, je voulais que cela soit fait au sein de mon application afin que le client n'ai pas a devoir renseigner l'adresse lui même a la main dans son navigateur.

J'ai donc utilisé les webview:

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
 
 
package com.example.dylan.myapplication;
 
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;
import android.app.Activity;
 
/**
 * Created by dylan on 04/06/2015.
 */
public class videoview extends MainActivity {
 
    //Fenetre d'attente
    private ProgressDialog progressDialog;
    //Controle d'affichage HTML
    private WebView webview;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.video_view);
 
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.video_view);
 
        webview = (WebView) findViewById(R.id.webview);
        WebSettings settings = webview.getSettings();
        settings.setJavaScriptEnabled(true);
        webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
 
        //Afficher une fenetre d'attente
        progressDialog = ProgressDialog.show(videoview.this, "Exemple de Webview", "Chargement...");
 
        //Creer le browser et charger l'url
        webview.setWebViewClient(new MyWebClient());
        webview.loadUrl("http://www.jeuxvideo.com");
 
 
 
    }
 
    /**
     * Surcharger l'evenement retour
     * @param keyCode
     * @param event
     * @return
     */
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
            webview.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
 
    /**
     * Configurer les evenements du Webview
     */
    public class MyWebClient extends WebViewClient {
 
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
 
        @Override
        public void onPageFinished(WebView view, String url) {
            //  Log.i(TAG, "Finished loading URL: " +url);
            if (progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
        }
 
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Log.e("Myapp", "Error: " + description);
            Toast.makeText(getApplicationContext(), "Erreur: "+description, Toast.LENGTH_LONG).show();
        }
    }
 
}
voici le code que j'utilise

Seulement lorsque je lance l'application et que je clique sur mon bouton ouvrant le webview j'ai la reponse suivante dans les logs:

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
06-08 12:32:16.011  14190-14190/com.example.dylan.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.dylan.myapplication, PID: 14190
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dylan.myapplication/com.example.dylan.myapplication.videoview}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2694)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)
            at android.app.ActivityThread.access$900(ActivityThread.java:178)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5944)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
     Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
            at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:359)
            at android.app.Activity.requestWindowFeature(Activity.java:3785)
            at com.example.dylan.myapplication.videoview.onCreate(videoview.java:33)
            at android.app.Activity.performCreate(Activity.java:6289)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2647)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)
************at android.app.ActivityThread.access$900(ActivityThread.java:178)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
************at android.os.Handler.dispatchMessage(Handler.java:102)
************at android.os.Looper.loop(Looper.java:145)
************at android.app.ActivityThread.main(ActivityThread.java:5944)
************at java.lang.reflect.Method.invoke(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:372)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
avez vous une idée d’où cela pourrait venir ?

cordialement