Advertisement
bit

Untitled

bit
Apr 17th, 2013
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. using System;
  2.  
  3. using Android.App;
  4. using Android.Content;
  5. using Android.Runtime;
  6. using Android.Views;
  7. using Android.Widget;
  8. using Android.OS;
  9. using Android.Webkit;
  10.  
  11. namespace MyWb
  12. {
  13. [Activity(Label = "MyWb", MainLauncher = true, Icon = "@drawable/icon")]
  14. public class MyWb : Activity
  15. {
  16. int count = 1;
  17.  
  18. protected override void OnCreate(Bundle bundle)
  19. {
  20. base.OnCreate(bundle);
  21.  
  22. // Set our view from the "main" layout resource
  23. SetContentView(Resource.Layout.Main);
  24.  
  25. // Get our button from the layout resource,
  26. // and attach an event to it
  27. Button button = FindViewById<Button>(Resource.Id.MyButton);
  28.  
  29. button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
  30.  
  31. WebView wv2 = (WebView)this.FindViewById(Resource.Id.webView1);
  32. wv2.SetWebViewClient(new WebViewClient());
  33. wv2.SetWebChromeClient(new MyWCC(this));
  34. wv2.Settings.JavaScriptEnabled = true;
  35. wv2.LoadUrl("http://www.script-tutorials.com/demos/199/index.html");
  36.  
  37. }
  38. }
  39.  
  40. public class MyWCC : WebChromeClient
  41. {
  42. private IValueCallback mUploadMessage;
  43. private static int FILECHOOSER_RESULTCODE = 1;
  44. private MyWb thisActivity = null;
  45.  
  46.  
  47. public MyWCC(MyWb context)
  48. {
  49. thisActivity = context;
  50. }
  51.  
  52. // For Android 3.0+
  53. // public override void OpenFileChooser(Android.Webkit.IValueCallback uploadMsg, String acceptType)
  54. // {
  55. //mUploadMessage = uploadMsg;
  56. //Intent i = new Intent(Intent.ActionGetContent);
  57. //i.AddCategory(Intent.CategoryOpenable);
  58. //i.SetType("*/*");
  59. // thisActivity.StartActivityForResult(Intent.CreateChooser(i, "File Browser"),
  60. //FILECHOOSER_RESULTCODE);
  61. //}
  62.  
  63. //For Android 4.1
  64. public void OpenFileChooser(IValueCallback uploadMsg, String acceptType, String capture)
  65. {
  66. mUploadMessage = uploadMsg;
  67. Intent i = new Intent(Intent.ActionGetContent);
  68. i.AddCategory(Intent.CategoryOpenable);
  69. i.SetType("image/*");
  70. thisActivity.StartActivityForResult(Intent.CreateChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
  71.  
  72. }
  73.  
  74.  
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement