Advertisement
bit

Untitled

bit
Apr 17th, 2013
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. package com.example.webviewtest2;
  2.  
  3. import android.net.Uri;
  4. import android.os.Bundle;
  5. import android.app.Activity;
  6. import android.content.Intent;
  7. import android.content.res.Configuration;
  8. import android.graphics.Bitmap;
  9. import android.view.Menu;
  10. import android.view.View;
  11. import android.webkit.ValueCallback;
  12. import android.webkit.WebChromeClient;
  13. import android.webkit.WebView;
  14. import android.webkit.WebViewClient;
  15. import android.widget.ProgressBar;
  16. import com.example.webviewtest2.R;
  17.  
  18. public class MyWb extends Activity {
  19. /** Called when the activity is first created. */
  20.  
  21. WebView web;
  22.  
  23. private ValueCallback<Uri> mUploadMessage;
  24. private final static int FILECHOOSER_RESULTCODE=1;
  25.  
  26. @Override
  27. protected void onActivityResult(int requestCode, int resultCode,
  28. Intent intent) {
  29. if(requestCode==FILECHOOSER_RESULTCODE)
  30. {
  31. if (null == mUploadMessage) return;
  32. Uri result = intent == null || resultCode != RESULT_OK ? null
  33. : intent.getData();
  34. mUploadMessage.onReceiveValue(result);
  35. mUploadMessage = null;
  36. }
  37. }
  38.  
  39. @Override
  40. public void onCreate(Bundle savedInstanceState) {
  41. super.onCreate(savedInstanceState);
  42. setContentView(R.layout.main);
  43.  
  44. web = (WebView) findViewById(R.id.webView1);
  45.  
  46. web = new WebView(this);
  47. web.getSettings().setJavaScriptEnabled(true);
  48. web.loadUrl("http://www.script-tutorials.com/demos/199/index.html");
  49. web.setWebViewClient(new myWebClient());
  50. web.setWebChromeClient(new WebChromeClient()
  51. {
  52. //The undocumented magic method override
  53. //Eclipse will swear at you if you try to put @Override here
  54. // For Android 3.0+
  55. public void openFileChooser(ValueCallback<Uri> uploadMsg) {
  56.  
  57. mUploadMessage = uploadMsg;
  58. Intent i = new Intent(Intent.ACTION_GET_CONTENT);
  59. i.addCategory(Intent.CATEGORY_OPENABLE);
  60. i.setType("image/*");
  61. MyWb.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);
  62.  
  63. }
  64.  
  65. // For Android 3.0+
  66. public void openFileChooser( ValueCallback uploadMsg, String acceptType ) {
  67. mUploadMessage = uploadMsg;
  68. Intent i = new Intent(Intent.ACTION_GET_CONTENT);
  69. i.addCategory(Intent.CATEGORY_OPENABLE);
  70. i.setType("*/*");
  71. MyWb.this.startActivityForResult(
  72. Intent.createChooser(i, "File Browser"),
  73. FILECHOOSER_RESULTCODE);
  74. }
  75.  
  76. //For Android 4.1
  77. public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
  78. mUploadMessage = uploadMsg;
  79. Intent i = new Intent(Intent.ACTION_GET_CONTENT);
  80. i.addCategory(Intent.CATEGORY_OPENABLE);
  81. i.setType("image/*");
  82. MyWb.this.startActivityForResult( Intent.createChooser( i, "File Chooser" ), MyWb.FILECHOOSER_RESULTCODE );
  83.  
  84. }
  85.  
  86. });
  87.  
  88.  
  89. setContentView(web);
  90.  
  91.  
  92. }
  93.  
  94. public class myWebClient extends WebViewClient
  95. {
  96. @Override
  97. public void onPageStarted(WebView view, String url, Bitmap favicon) {
  98. // TODO Auto-generated method stub
  99. super.onPageStarted(view, url, favicon);
  100. }
  101.  
  102. @Override
  103. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  104. // TODO Auto-generated method stub
  105.  
  106. view.loadUrl(url);
  107. return true;
  108.  
  109. }
  110.  
  111. @Override
  112. public void onPageFinished(WebView view, String url) {
  113. // TODO Auto-generated method stub
  114. super.onPageFinished(view, url);
  115.  
  116. }
  117. }
  118.  
  119. //flipscreen not loading again
  120. @Override
  121. public void onConfigurationChanged(Configuration newConfig){
  122. super.onConfigurationChanged(newConfig);
  123. }
  124.  
  125. // To handle "Back" key press event for WebView to go back to previous screen.
  126. /*@Override
  127. public boolean onKeyDown(int keyCode, KeyEvent event)
  128. {
  129. if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
  130. web.goBack();
  131. return true;
  132. }
  133. return super.onKeyDown(keyCode, event);
  134. }*/
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement