document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package mediatutorial.web.id.metuwebbrowser;
  2.  
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.support.v7.app.ActionBarActivity;
  6. import android.os.Bundle;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.webkit.WebSettings;
  11. import android.webkit.WebView;
  12. import android.webkit.WebViewClient;
  13. import android.widget.EditText;
  14.  
  15. import java.net.URL;
  16.  
  17. public class MainActivity extends ActionBarActivity {
  18.     String theUrl = "";
  19.     public WebView webBrowserKu;
  20.  
  21.     protected void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.activity_main);
  24.         webBrowserKu = (WebView)findViewById(R.id.myWebView);
  25.         webBrowserKu.setWebViewClient(new WebViewClient());
  26.         WebSettings theWebSetting = webBrowserKu.getSettings();
  27.         theWebSetting.setJavaScriptEnabled(true);
  28.         //
  29.         //yuk kita menangkap intent (bila ada)
  30.         Intent intent = getIntent();
  31.         Uri data = intent.getData();
  32.         URL url = null;
  33.         try {
  34.             url = new URL(data.getScheme(), data.getHost(),data.getPath());
  35.         } catch (Exception e) {
  36.             e.printStackTrace();
  37.         }
  38.         if(url != null){
  39.             theUrl = url.toString();
  40.             webBrowserKu.loadUrl(theUrl);
  41.             //
  42.             EditText theEditText = (EditText)findViewById(R.id.urlTxt);
  43.             theEditText.setText(theUrl);
  44.         }
  45.  
  46.         //berikut juga bisa digunakan
  47.         /*String myString = null;
  48.         Intent intent = getIntent();
  49.         myString = intent.getDataString();
  50.         if(myString != null){
  51.             webBrowserKu.loadUrl(myString);
  52.             //
  53.             EditText theEditText = (EditText)findViewById(R.id.urlTxt);
  54.             theEditText.setText(myString);
  55.         }*/
  56.  
  57.     }
  58.  
  59.  
  60.     @Override
  61.     public boolean onCreateOptionsMenu(Menu menu) {
  62.         // Inflate the menu; this adds items to the action bar if it is present.
  63.         getMenuInflater().inflate(R.menu.menu_main, menu);
  64.         return true;
  65.     }
  66.  
  67.     @Override
  68.     public boolean onOptionsItemSelected(MenuItem item) {
  69.         // Handle action bar item clicks here. The action bar will
  70.         // automatically handle clicks on the Home/Up button, so long
  71.         // as you specify a parent activity in AndroidManifest.xml.
  72.         int id = item.getItemId();
  73.  
  74.         //noinspection SimplifiableIfStatement
  75.         if (id == R.id.action_settings) {
  76.             return true;
  77.         }
  78.  
  79.         return super.onOptionsItemSelected(item);
  80.     }
  81.  
  82.     public void gotoUrl(View view) {
  83.         EditText theEditText = (EditText)findViewById(R.id.urlTxt);
  84.         theUrl = theEditText.getText().toString();
  85.         //
  86.         webBrowserKu.loadUrl(theUrl);
  87.  
  88.     }
  89.  
  90.     public void goRefresh(MenuItem item) {
  91.         webBrowserKu.reload();
  92.     }
  93.  
  94.     public void goStop(MenuItem item) {
  95.         webBrowserKu.stopLoading();
  96.     }
  97.  
  98.     public void goBack(MenuItem item) {
  99.         webBrowserKu.goBack();
  100.     }
  101.  
  102.     public void goForward(MenuItem item) {
  103.         webBrowserKu.goForward();
  104.     }
  105. }
');