Advertisement
bit

Untitled

bit
Apr 27th, 2013
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 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.  
  41. partial class MyWCC : WebChromeClient
  42. {
  43. private IValueCallback mUploadMessage;
  44. private static int FILECHOOSER_RESULTCODE = 1;
  45. private MyWb thisActivity = null;
  46.  
  47.  
  48. public MyWCC(MyWb context)
  49. {
  50. thisActivity = context;
  51. }
  52.  
  53. // For Android 3.0+
  54. // public override void OpenFileChooser(Android.Webkit.IValueCallback uploadMsg, String acceptType)
  55. // {
  56. //mUploadMessage = uploadMsg;
  57. //Intent i = new Intent(Intent.ActionGetContent);
  58. //i.AddCategory(Intent.CategoryOpenable);
  59. //i.SetType("*/*");
  60. // thisActivity.StartActivityForResult(Intent.CreateChooser(i, "File Browser"),
  61. //FILECHOOSER_RESULTCODE);
  62. //}
  63.  
  64. //For Android 4.1
  65. [Java.Interop.Export]
  66. public void OpenFileChooser(IValueCallback uploadMsg, Java.Lang.String acceptType, Java.Lang.String capture)
  67. {
  68. mUploadMessage = uploadMsg;
  69. Intent i = new Intent(Intent.ActionGetContent);
  70. i.AddCategory(Intent.CategoryOpenable);
  71. i.SetType("image/*");
  72. thisActivity.StartActivityForResult(Intent.CreateChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
  73.  
  74. }
  75.  
  76.  
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement