AI2 Component  (Version nb184)
WebViewActivity.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2009-2011 Google, All Rights reserved
3 // Copyright 2011-2018 MIT, All rights reserved
4 // Released under the Apache License, Version 2.0
5 // http://www.apache.org/licenses/LICENSE-2.0
6 
7 package com.google.appinventor.components.runtime;
8 
9 import android.content.Intent;
10 import android.net.Uri;
11 import android.os.Bundle;
12 import android.util.Log;
13 import android.webkit.WebView;
14 import android.webkit.WebViewClient;
15 
31 public final class WebViewActivity extends AppInventorCompatActivity {
32 
33  @Override
34  public void onCreate(Bundle savedInstanceState) {
35  WebView webview;
36 
37  super.onCreate(savedInstanceState);
38  webview = new WebView(this);
39  webview.getSettings().setJavaScriptEnabled(true);
40  webview.setWebViewClient(new WebViewClient() {
41  @Override
42  public boolean shouldOverrideUrlLoading(WebView view, String url) {
43  Log.i("WebView", "Handling url " + url);
44  Uri uri = Uri.parse(url);
45  String scheme = uri.getScheme();
46  if (scheme.equals(Form.APPINVENTOR_URL_SCHEME)) {
47  Intent resultIntent = new Intent();
48  resultIntent.setData(uri);
49  setResult(RESULT_OK, resultIntent);
50  finish();
51  } else {
52  view.loadUrl(url);
53  }
54  return true;
55  }
56  });
57  setContentView(webview);
58 
59  Intent uriIntent = getIntent();
60  if (uriIntent != null && uriIntent.getData() != null) {
61  Uri uri = uriIntent.getData();
62  String scheme = uri.getScheme();
63  String host = uri.getHost();
64  Log.i("WebView", "Got intent with URI: " + uri + ", scheme="
65  + scheme + ", host=" + host);
66  webview.loadUrl(uri.toString());
67  }
68  }
69 }
com.google.appinventor.components.runtime.WebViewActivity
Definition: WebViewActivity.java:31
com.google.appinventor.components.runtime.Form.APPINVENTOR_URL_SCHEME
static final String APPINVENTOR_URL_SCHEME
Definition: Form.java:136
com.google.appinventor.components.runtime.WebViewActivity.onCreate
void onCreate(Bundle savedInstanceState)
Definition: WebViewActivity.java:34
com.google.appinventor.components.runtime.AppInventorCompatActivity.setContentView
void setContentView(View view)
Definition: AppInventorCompatActivity.java:190
com.google.appinventor.components.runtime.AppInventorCompatActivity
Definition: AppInventorCompatActivity.java:40
com.google.appinventor.components.runtime.Form
Definition: Form.java:126