Advertisement
bit

Untitled

bit
May 1st, 2013
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 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.SetWebChromeClient(new MyWCC());
  35. wv2.Settings.JavaScriptEnabled = true;
  36. wv2.LoadUrl("http://www.script-tutorials.com/demos/199/index.html");
  37.  
  38.  
  39. }
  40. }
  41.  
  42. partial class MyWCC : WebChromeClient
  43. {
  44. private IValueCallback mUploadMessage;
  45. private static int FILECHOOSER_RESULTCODE = 1;
  46. private MyWb thisActivity = null;
  47.  
  48.  
  49. public MyWCC(MyWb context)
  50. {
  51. thisActivity = context;
  52. }
  53.  
  54. // For Android 3.0+
  55. // public override void OpenFileChooser(Android.Webkit.IValueCallback uploadMsg, String acceptType)
  56. // {
  57. //mUploadMessage = uploadMsg;
  58. //Intent i = new Intent(Intent.ActionGetContent);
  59. //i.AddCategory(Intent.CategoryOpenable);
  60. //i.SetType("*/*");
  61. // thisActivity.StartActivityForResult(Intent.CreateChooser(i, "File Browser"),
  62. //FILECHOOSER_RESULTCODE);
  63. //}
  64.  
  65. //For Android 4.1
  66. [Java.Interop.Export]
  67. public void openFileChooser(IValueCallback uploadMsg, Java.Lang.String acceptType, Java.Lang.String capture)
  68. {
  69. mUploadMessage = uploadMsg;
  70. Intent i = new Intent(Intent.ActionGetContent);
  71. i.AddCategory(Intent.CategoryOpenable);
  72. i.SetType("image/*");
  73. thisActivity.StartActivityForResult(Intent.CreateChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
  74.  
  75. }
  76.  
  77.  
  78. }
  79.  
  80. //partial class MyWCC : WebChromeClient
  81. //{
  82. // private IValueCallback mUploadMessage;
  83. // private static int FILECHOOSER_RESULTCODE = 1;
  84.  
  85. // [Java.Interop.Export]
  86. // public void openFileChooser(IValueCallback uploadMsg, Java.Lang.String acceptType, Java.Lang.String capture)
  87. // {
  88. // mUploadMessage = uploadMsg;
  89. // Intent i = new Intent(Intent.ActionGetContent);
  90. // i.AddCategory(Intent.CategoryOpenable);
  91. // i.SetType("image/*");
  92. // thisActivity.StartActivityForResult(Intent.CreateChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
  93.  
  94. // }
  95. //}
  96.  
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement