Advertisement
bit

Untitled

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