Example usage for android.webkit WebView setWebContentsDebuggingEnabled

List of usage examples for android.webkit WebView setWebContentsDebuggingEnabled

Introduction

In this page you can find the example usage for android.webkit WebView setWebContentsDebuggingEnabled.

Prototype

public static void setWebContentsDebuggingEnabled(boolean enabled) 

Source Link

Document

Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this application.

Usage

From source file:upv.welcomeincoming.app.ARViewActivity.java

@SuppressLint("NewApi")
@Override//from  ww w. jav  a2 s .co  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_architect_view);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    //Wikitude: Cambio en WebView para Android KitKat
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }

    // establecer AR-view
    this.architectView = (ArchitectView) this.findViewById(R.id.architectView);

    //Inicializar clave de Wikitude SDK (si se posee)
    // (en caso contrario, aparece una marca de agua en la architectView)
    final ArchitectConfig config = new ArchitectConfig("" /* license key */ );

    this.architectView.onCreate(config);

    // listener del locationProvider, maneja los cambios de localizacion
    this.locationListener = new LocationListener() {
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onLocationChanged(final Location location) {
            if (location != null) {
                // establecer ultima localizacion
                ARViewActivity.this.lastKnownLocaton = location;
                if (ARViewActivity.this.architectView != null) {
                    // chequeamos si la localizacion tiene altitud a un determinado nivel de exactitud (para invocar al metodo adecuado en la ARView)
                    if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) {
                        ARViewActivity.this.architectView.setLocation(location.getLatitude(),
                                location.getLongitude(), location.getAltitude(), location.getAccuracy());
                    } else {
                        ARViewActivity.this.architectView.setLocation(location.getLatitude(),
                                location.getLongitude(),
                                location.hasAccuracy() ? location.getAccuracy() : 1000);
                    }
                }
            }
        }
    };

    // locationProvider
    this.locationProvider = new LocationProvider(this, this.locationListener);
}

From source file:me.jvdv.bancwear.BaseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    WebView.setWebContentsDebuggingEnabled(true);

    mWebView.setWebChromeClient(new WebChromeClient());
    mWebView.setWebViewClient(new WebViewClient());

    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override//w ww . ja  va 2s  .c o  m
        public void onReceive(Context context, Intent intent) {
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
            if (sentToken) {
                blaat(getString(R.string.gcm_send_message));
            } else {
                blaat(getString(R.string.token_error_message));
            }
        }
    };

    // Registering BroadcastReceiver
    registerReceiver();

    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }
}

From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.WebViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.web_fragment, container, false);
    ButterKnife.inject(this, view);
    isError = false;//from www  .  j ava2s.  c o m
    //Needed in order to run within appium
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
        WebView.setWebContentsDebuggingEnabled(true);

    webView.setWebViewClient(generateWebViewClient());
    webView.loadUrl(getActivity().getString(R.string.default_url));
    return view;
}

From source file:com.google.blockly.android.codegen.CodeGeneratorService.java

@Override
public void onCreate() {
    mHandler = new Handler();
    mWebview = new WebView(this);
    mWebview.getSettings().setJavaScriptEnabled(true);
    mWebview.setWebChromeClient(new WebChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }//from   ww w.j a  v  a 2s. c  o  m
    mWebview.addJavascriptInterface(new BlocklyJavascriptInterface(), "BlocklyJavascriptInterface");

    mWebview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            synchronized (this) {
                mReady = true;
            }
            handleRequest();
        }
    });
    mWebview.loadUrl(BLOCKLY_COMPILER_PAGE);
}

From source file:justforcommunity.radiocom.activities.ContentDetail.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_contentdetail);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from  w w w  . j  av a2 s  .co  m*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    prefs = this.getSharedPreferences(GlobalValues.prefName, Context.MODE_PRIVATE);
    edit = prefs.edit();

    detail_web = (WebView) findViewById(R.id.detail_web);

    content = getIntent().getStringExtra(GlobalValues.EXTRA_CONTENT);

    detail_web.setBackgroundColor(Color.WHITE);

    title = getIntent().getStringExtra(GlobalValues.EXTRA_TITLE);

    getSupportActionBar().setTitle(title);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    try {
        content = content.replaceAll("style=\".+?\"", "");
    } catch (Exception e) {

    }

    String fontscript = "";
    String script = "<style type='text/css' >p{width:100%;}img{width:100%;height:auto;-webkit-transform: translate3d(0px,0px,0px);}a,h1,h2,h3,h4,h5,h6{color:"
            + GlobalValues.colorHTML
            + ";}div,p,span,a {max-width: 100%;}iframe{width:100%;height:auto;}</style>";

    detail_web.loadDataWithBaseURL(
            GlobalValues.baseURLWEB, "<html><head>" + fontscript + script
                    + "</head><body style=\"font-family:HelveticaNeue-Light; \">" + content + "</body></html>",
            "text/html", "utf-8", "");
    detail_web.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if ((url != null && url.startsWith("http://")) || (url != null && url.startsWith("https://"))) {
                view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                return true;
            } else {
                return false;
            }

        }

        public void onPageFinished(WebView view, String url) {
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        }
    });
    detail_web.getSettings().setDomStorageEnabled(true);
    detail_web.getSettings().setJavaScriptEnabled(true);

    App appliaction = (App) getApplication();
    Tracker mTracker = appliaction.getDefaultTracker();
    mTracker.setScreenName(getString(R.string.content_activity));
    mTracker.send(new HitBuilders.ScreenViewBuilder().build());

}

From source file:com.centurylink.mdw.mobile.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  w  w w .j  a v a  2  s.  c  o m

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    settings = new Settings(getApplicationContext());

    webView = (WebView) findViewById(R.id.webview);
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setSupportZoom(true);
    // webView.getSettings().setBuiltInZoomControls(true);
    // allow debugging with chrome dev tools
    WebView.setWebContentsDebuggingEnabled(true);

    // do not cache in debug
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    webView.getSettings().setAppCacheEnabled(false);
    webView.clearCache(true);

}

From source file:com.scm.reader.resultPage.ui.ItemViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from   ww w  .  j a v  a  2  s  . co m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_result, container, false);

    mWebView = (WebView) v.findViewById(R.id.webView);

    // set WebViewClient
    mWebViewClient = createWebViewClient(getActivity());
    mWebView.setWebViewClient(mWebViewClient);

    final ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.progressBar);

    mWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {
            if (progress == 100) {
                progressBar.setVisibility(View.GONE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(progress);
            }
        }
    });

    initializeWebView(mWebView);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (0 != (getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }

    mWebView.loadUrl(mUrl);

    return v;
}

From source file:at.kropf.curriculumvitae.augmented.AbstractArchitectCamActivity.java

/** Called when the activity is first created. */
@SuppressLint("NewApi")
@Override//from   w w w .ja v  a 2 s .c  o m
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* pressing volume up/down should cause music volume changes */
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    /* set samples content view */
    this.setContentView(this.getContentViewId());

    this.setTitle(this.getActivityTitle());

    /*  
     *   this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml
     *   If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse.
     *   You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place.
     *   Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }

    /* set AR-view for life-cycle notifications etc. */
    this.architectView = (ArchitectView) this.findViewById(this.getArchitectViewId());

    /* pass SDK key if you have one, this one is only valid for this package identifier and must not be used somewhere else */
    final StartupConfiguration config = new StartupConfiguration(this.getWikitudeSDKLicenseKey(),
            this.getFeatures(), this.getCameraPosition());

    try {
        /* first mandatory life-cycle notification */
        this.architectView.onCreate(config);
    } catch (RuntimeException rex) {
        this.architectView = null;
        Toast.makeText(getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT).show();
        Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex);
    }

    // set accuracy listener if implemented, you may e.g. show calibration prompt for compass using this listener
    this.sensorAccuracyListener = this.getSensorAccuracyListener();

    // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'" is forwarded to this listener, use this to interact between JS and native Android activity/fragment
    this.urlListener = this.getUrlListener();

    // register valid urlListener in architectView, ensure this is set before content is loaded to not miss any event
    if (this.urlListener != null && this.architectView != null) {
        this.architectView.registerUrlListener(this.getUrlListener());
    }

    if (hasGeo()) {
        // listener passed over to locationProvider, any location update is handled here
        this.locationListener = new LocationListener() {

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
            }

            @Override
            public void onProviderEnabled(String provider) {
            }

            @Override
            public void onProviderDisabled(String provider) {
            }

            @Override
            public void onLocationChanged(final Location location) {
                // forward location updates fired by LocationProvider to architectView, you can set lat/lon from any location-strategy
                if (location != null) {
                    // sore last location as member, in case it is needed somewhere (in e.g. your adjusted project)
                    AbstractArchitectCamActivity.this.lastKnownLocaton = location;
                    if (AbstractArchitectCamActivity.this.architectView != null) {
                        // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information)
                        if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) {
                            AbstractArchitectCamActivity.this.architectView.setLocation(location.getLatitude(),
                                    location.getLongitude(), location.getAltitude(), location.getAccuracy());
                        } else {
                            AbstractArchitectCamActivity.this.architectView.setLocation(location.getLatitude(),
                                    location.getLongitude(),
                                    location.hasAccuracy() ? location.getAccuracy() : 1000);
                        }
                    }
                }
            }
        };

        // locationProvider used to fetch user position
        this.locationProvider = getLocationProvider(this.locationListener);
    } else {
        this.locationProvider = null;
        this.locationListener = null;
    }
}

From source file:com.example.traveljoin.wikitude.AbstractArchitectCamFragmentV4.java

@SuppressLint("NewApi")
@Override/*from w w  w.  j ava 2s. c  o m*/
public void onActivityCreated(final Bundle bundle) {
    super.onActivityCreated(bundle);

    // set architectView, important for upcoming lifecycle calls
    this.architectView = (ArchitectView) this.getView().findViewById(getArchitectViewId());

    // pass license key to architectView while creating it
    final ArchitectConfig config = new ArchitectConfig(this.getWikitudeSDKLicenseKey());

    // forwards mandatory life-cycle-events, unfortunately there is no onPostCreate() event in fragments so we have to call it that way
    try {
        /* first mandatory life-cycle notification */
        this.architectView.onCreate(config);
        this.architectView.onPostCreate();
    } catch (RuntimeException rex) {
        this.architectView = null;
        Toast.makeText(getActivity().getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT)
                .show();
        Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex);
    }

    /*  
     *   this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml
     *   If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse.
     *   You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place.
     *   Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (0 != (getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }

    try {

        // load architectView's content
        this.architectView.load(this.getARchitectWorldPath());

        if (this.getInitialCullingDistanceMeters() != ArchitectViewHolderInterface.CULLING_DISTANCE_DEFAULT_METERS) {
            // set the culling distance - meaning: the maximum distance to render geo-content
            this.architectView.setCullingDistance(this.getInitialCullingDistanceMeters());
        }

    } catch (IOException e) {
        // unexpected, if error occurs here your path is invalid
        e.printStackTrace();
    }

    // listener passed over to locationProvider, any location update is handled here
    this.locationListener = new LocationListener() {

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onLocationChanged(final Location location) {
            if (location != null) {
                AbstractArchitectCamFragmentV4.this.lastKnownLocaton = location;
                if (AbstractArchitectCamFragmentV4.this.architectView != null) {
                    // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information)
                    if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) {
                        AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(),
                                location.getLongitude(), location.getAltitude(), location.getAccuracy());
                    } else {
                        AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(),
                                location.getLongitude(),
                                location.hasAccuracy() ? location.getAccuracy() : 1000);
                    }
                }
            }
        }
    };

    // set accuracy listener if implemented, you may e.g. show calibration prompt for compass using this listener
    this.sensorAccuracyListener = this.getSensorAccuracyListener();

    // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'" is forwarded to this listener, use this to interact between JS and native Android activity/fragment
    this.urlListener = this.getUrlListener();

    // register valid urlListener in architectView, ensure this is set before content is loaded to not miss any event
    if (this.urlListener != null) {
        this.architectView.registerUrlListener(this.getUrlListener());
    }

    // locationProvider used to fetch user position
    this.locationProvider = this.getLocationProvider(this.locationListener);

}

From source file:com.spectralinsights.locar.AbstractArchitectCamFragmentV4.java

@SuppressLint("NewApi")
@Override//from w  w  w .  ja  v  a 2  s  . c o  m
public void onActivityCreated(final Bundle bundle) {
    super.onActivityCreated(bundle);

    // set architectView, important for upcoming lifecycle calls
    this.architectView = (ArchitectView) this.getView().findViewById(getArchitectViewId());

    // pass license key to architectView while creating it
    final StartupConfiguration config = new StartupConfiguration(this.getWikitudeSDKLicenseKey(),
            ArchitectView.getSupportedFeaturesForDevice(getActivity()));

    // forwards mandatory life-cycle-events, unfortunately there is no onPostCreate() event in fragments so we have to call it that way
    try {
        /* first mandatory life-cycle notification */
        this.architectView.onCreate(config);
        this.architectView.onPostCreate();
    } catch (RuntimeException rex) {
        this.architectView = null;
        Toast.makeText(getActivity().getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT)
                .show();
        Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex);
    }

    /*  
     *   this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml
     *   If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse.
     *   You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place.
     *   Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (0 != (getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }

    try {

        // load architectView's content
        this.architectView.load(this.getARchitectWorldPath());

        if (this.getInitialCullingDistanceMeters() != ArchitectViewHolderInterface.CULLING_DISTANCE_DEFAULT_METERS) {
            // set the culling distance - meaning: the maximum distance to render geo-content
            this.architectView.setCullingDistance(this.getInitialCullingDistanceMeters());
        }

    } catch (IOException e) {
        // unexpected, if error occurs here your path is invalid
        e.printStackTrace();
    }

    // listener passed over to locationProvider, any location update is handled here
    this.locationListener = new LocationListener() {

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onLocationChanged(final Location location) {
            if (location != null) {
                AbstractArchitectCamFragmentV4.this.lastKnownLocaton = location;
                if (AbstractArchitectCamFragmentV4.this.architectView != null) {
                    // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information)
                    if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) {
                        AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(),
                                location.getLongitude(), location.getAltitude(), location.getAccuracy());
                    } else {
                        AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(),
                                location.getLongitude(),
                                location.hasAccuracy() ? location.getAccuracy() : 1000);
                    }
                }
            }
        }
    };

    // set accuracy listener if implemented, you may e.g. show calibration prompt for compass using this listener
    this.sensorAccuracyListener = this.getSensorAccuracyListener();

    // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'" is forwarded to this listener, use this to interact between JS and native Android activity/fragment
    this.urlListener = this.getUrlListener();

    // register valid urlListener in architectView, ensure this is set before content is loaded to not miss any event
    if (this.urlListener != null) {
        this.architectView.registerUrlListener(this.getUrlListener());
    }

    // locationProvider used to fetch user position
    this.locationProvider = this.getLocationProvider(this.locationListener);

}