筆記

          way

          Andriod webview實現文件上傳

          Andriod 到3.2版本為止,webview方式下使用<input type="file" />點擊后都沒有反應。實際上頂層是有隱含的接口沒實現的,可以自己重寫這個方法來實現。以phonegap為例:

          public class App extends DroidGap {
              
          private ValueCallback<Uri> mUploadMessage;
              
          private final static int FILECHOOSER_RESULTCODE = 1;

              
          /** Called when the activity is first created. */
              @Override
              
          public void onCreate(Bundle savedInstanceState) {
                  
          super.onCreate(savedInstanceState);
                  
          super.init();
                  
          // WebView wv = new WebView(this);
                  
          // wv.setWebViewClient(new WebViewClient());
                  this.appView.setWebChromeClient(new CordovaChromeClient(App.this) {
                      
          // For Android 3.0+
                      public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
                          mUploadMessage 
          = uploadMsg;
                          Intent i 
          = new Intent(Intent.ACTION_GET_CONTENT);
                          i.addCategory(Intent.CATEGORY_OPENABLE);
                          i.setType(
          "image/*");
                          App.
          this.startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
                      }

                      
          // The undocumented magic method override
                      
          // Eclipse will swear at you if you try to put @Override here
                      public void openFileChooser(ValueCallback<Uri> uploadMsg) {
                          mUploadMessage 
          = uploadMsg;
                          Intent i 
          = new Intent(Intent.ACTION_GET_CONTENT);
                          i.addCategory(Intent.CATEGORY_OPENABLE);
                          i.setType(
          "image/*");
                          App.
          this.startActivityForResult(Intent.createChooser(i, "File Chooser"), App.FILECHOOSER_RESULTCODE);
                      }
                  });

                  
          // setContentView(wv);
                  super.loadUrl("file:///android_asset/www/login.html");
              }

              @Override
              
          protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
                  
          if (requestCode == FILECHOOSER_RESULTCODE) {
                      
          if (null == mUploadMessage)
                          
          return;
                      Uri result 
          = intent == null || resultCode != RESULT_OK ? null : intent.getData();
                      mUploadMessage.onReceiveValue(result);
                      mUploadMessage 
          = null;
                  }
              }
          }
          如果直接的webview方式,extends WebChromeClient即可。 參考:http://stackoverflow.com/questions/5907369/file-upload-in-webview

          posted on 2012-03-12 12:54 yuxh 閱讀(5336) 評論(1)  編輯  收藏 所屬分類: workAndroid

          評論

          # re: Andriod webview實現文件上傳 2012-08-05 17:32 xiuukin

          樓主能不能發個安卓的實例 謝謝啦  回復  更多評論   

          導航

          <2012年3月>
          26272829123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          統計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          收藏夾

          博客

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 望谟县| 马龙县| 高陵县| 长春市| 平乡县| 新巴尔虎左旗| 咸宁市| 尚志市| 河曲县| 阿尔山市| 香河县| 吴忠市| 清水县| 绩溪县| 彩票| 兴义市| 瑞丽市| 抚顺市| 信阳市| 钟山县| 繁峙县| 新巴尔虎右旗| 沁阳市| 麦盖提县| 杭锦后旗| 嘉兴市| 延寿县| 中超| 同心县| 梧州市| 茶陵县| 绥中县| 张家川| 泸州市| 仪征市| 定边县| 瑞昌市| 灌南县| 武隆县| 浮山县| 岳池县|