我已经在代码里加了mWebView.getSettings().setPluginState(PluginState.ON);
但是还是不能播放flash,一片空白啊,是在真机上,不是模拟器!
browser是可以播放的,已经安装了flash 10.3 for android接下来贴上我的代码,有需要的可以参考:
package com.WebViewTest;import java.io.File;
import java.io.FileOutputStream;import com.WebViewTest.R;import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Picture;
public class WebViewTest extends Activity
{
private WebView mWebView;
    private EditText editText;  
    private Button   go;
    private Handler mHandler;    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.main);
      //  WebViewFragment fragment = (WebViewFragment)getFragmentManager().findFragmentById(R.id.fragment);/*android3.0 new feature*/
       // mWebView = fragment.getWebView(); /*android3.0 new feature*/
        mWebView = (WebView) findViewById(R.id.webView);
        editText = (EditText) findViewById(R.id.editText);  
        go = (Button)findViewById(R.id.go);  
        mHandler = new Handler();
       // WebView mWebView = new WebView(this);
        //setContentView(mWebView);
        getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setPluginState(PluginState.ON);
    //    mWebView.getSettings().setPluginsEnabled(true);
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.getSettings().setEnableSmoothTransition(true); /*android3.0 new feature*/
        mWebView.getSettings().setLoadsImagesAutomatically(true);
     //   mWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
        mWebView.setFocusableInTouchMode(true);
        mWebView.setScrollbarFadingEnabled(false);
        mWebView.setSaveEnabled(true);
        WebView.enablePlatformNotifications();
        registerForContextMenu(mWebView);
        
        final Activity activity = this;
 
        mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
         /*  WebViewTest.this.getWindow().setFeatureInt(
Window.FEATURE_PROGRESS, progress * 100);*/
activity.setTitle("Loading...");
         editText.setText(mWebView.getUrl());
            // Activities and WebViews measure progress with different scales.
            // The progress meter will automatically disappear when we reach 100%
            activity.setProgress(progress * 100);
            if(progress == 100){
             activity.setTitle("Loading Finish!");
            }
          }
        });
        mWebView.setWebViewClient(new WebViewClient() {
           
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
          
public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon);
}
public void onPageFinished(WebView view, String url) {
  /*      mHandler.post(new Runnable() {
         public void run() {
         mWebView.loadUrl("javascript:showAndroidToast('hello')");
         }
         });*/
super.onPageFinished(view, url);
}
         
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
          }
        });
    //    Log.i("=============",""+ mWebView);
        go.setOnClickListener(new OnClickListener() {  
            public void onClick(View v) {
             if(!editText.getText().toString().startsWith("http://") && !editText.getText().toString().startsWith("file:///")){
                    mWebView.loadUrl("http://"+editText.getText().toString());
         mWebView.requestFocus();
             }else{
             mWebView.loadUrl(editText.getText().toString());
             mWebView.requestFocus();
             }
            }  
        });
        mWebView.loadUrl("file:///mnt/sdcard/v.html");
    }
/* @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}*/
    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
             /*   && event.getAction() == KeyEvent.ACTION_UP */
                && editText.isFocused()) {
         /*if( editText.getText().subSequence(1, 4).toString().equal("http")){
         mWebView.loadUrl(editText.getText().toString());
         mWebView.requestFocus();
         }*/
         if(!editText.getText().toString().startsWith("http://") && !editText.getText().toString().startsWith("file:///")){
                mWebView.loadUrl("http://"+editText.getText().toString());
     mWebView.requestFocus();
         }else{
         // Log.i("=========3333333=======","http ???" + editText.getText().subSequence(1, 4).toString());
         mWebView.loadUrl(editText.getText().toString());
         mWebView.requestFocus();
         }
            return true;
        }
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
mWebView.goBack();
mWebView.requestFocus();
return true;
}
if (event.getKeyCode() == KeyEvent.KEYCODE_ALT_RIGHT && mWebView.canGoForward()) {
mWebView.goForward();
mWebView.requestFocus();
return true;
}
        return super.dispatchKeyEvent(event);
    }
//    public class JavaScriptInterface {
//        Context mContext;
//
//        /** Instantiate the interface and set the context */
//        JavaScriptInterface(Context c) {
//            mContext = c;
//        }
//
//        /** Show a toast from the web page */
//        public void showToast(String toast) {
//         Log.i("=======================================","say hello is clicked");
//            Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
//        }
//    }
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo){
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.context_menu, menu);
    }
    @Override
    public boolean onContextItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
        case R.id.search:
        //    mWebView.showFindDialog("", true);/*android3.0 new feature*/
            return true;
        case R.id.save:
        /* String savename = mWebView.getUrl().toString();
         ValueCallback<String> callback = null;
         mWebView.saveWebArchive("/mnt/sdcard/Download/"+savename,true,callback);
         Log.i("~~~~~~~~~~~~~callback~~~~~~~~~~~~~~","" + callback);
         mWebView.loadUrl("file:///mnt/sdcard/Download/"+savename);*/
         Picture pic = mWebView.capturePicture();
         int width = pic.getWidth();
         int height = pic.getHeight();
         if (width > 0 && height > 0) {
         Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
         Canvas canvas = new Canvas(bmp);
         pic.draw(canvas);
         try {
             String fileName = "sdcard/ss/" + System.currentTimeMillis() + ".png";
             File outfile = new File(fileName);
             Log.i("==============Create File==============",""+outfile.exists());
             if(!outfile.exists()){
              outfile.createNewFile();
              }
             else {FileOutputStream fos = new FileOutputStream(fileName);
             if (fos != null) {
                   bmp.compress(Bitmap.CompressFormat.PNG, 90, fos);
                   fos.close();
               }
            Toast.makeText(getApplicationContext(), "截图成功,文件名是:" + fileName, Toast.LENGTH_SHORT).show();
              }
          } catch (Exception e) {
                      e.printStackTrace();
                   }
          }
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
  /*      return false;*/
    }
    @Override
    protected void onDestroy() {
        mWebView.destroy();
        super.onDestroy();
    }
}

解决方案 »

  1.   

    和你的android版本有关吧?android2.2之前是不能支持flash
      

  2.   

    我在几个论坛都问了,没人理。感觉在我们国家对android的研发还很肤浅,只做一些皮面上的功夫,深入的人很少,大家努力啊~~!
      

  3.   

    flash Player对CPU有要求,非X86构架的只支持arm v7以上的处理器,这点道是确实存在。
      

  4.   

    谢谢各位那么晚了还顶我的帖子,机器里的browser倒是可以用flash player播放swf文件,自己写的webview却不能同样在/data/data/com.WebViewTest/app_plugins有com.adobe.flashplayer
      

  5.   

    同学,你这个问题很大了webview可以直接播放flash吗。。当然要加上flash播放器
    给你代码参考。。很简单的
    webview_main.loadUrl("file:///android_asset/sample/index.html");<object width="300" height="200">
    <param name="movie"
    value="http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf"></param>
    <param name="flashvars"
    value="src=http%3A%2F%2Fosmf.org%2Fvideos%2Fcathy2.flv"></param>
    <param name="allowFullScreen" value="true"></param>
    <param name="allowscriptaccess" value="always"></param>
    <embed
    src="http://10.1.1.137:8080/testRed5.swf"
    type="application/x-shockwave-flash" allowscriptaccess="always"
    allowfullscreen="true" width="500" height="300"
    flashvars="src=http%3A%2F%2Fosmf.org%2Fvideos%2Fcathy2.flv">
    </embed>
    </object>
      

  6.   

    如果你要动态播放地址,可以酱紫webView.loadData。用string组合成html代码。。
      

  7.   

    我写的html<html>
    <head>
    </head>
    <body>
    <embed src="/mnt/sdcard/cis_base.swf" allowFullScreen="true" quality="high" width="1024" height="500" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash"></embed>
    </body>
    </html>上面java代码里 mWebView.loadUrl("file:///mnt/sdcard/v.html");这个网页显示空白一片
      

  8.   

    首先我有个问题src="/mnt/sdcard/cis_base.swf"你认为html能找到你的sd卡中的内容吗。。
      

  9.   

    我调用的网络上的html,只设置了这一项webSettings.setPluginState(WebSettings.PluginState.ON);就能播放网页上的flash了,初学者,希望对楼主有帮助,呵呵
      

  10.   

    你用果tomcat吗,你把你的cis_base.swf放到tomcat上面然后src="http://你的ip:8080/你的web应用/cis_base.swf"就可以了。
      

  11.   

    我用browser读我的html是可以播放嵌入的.swf的,tomcat没用过,等下去查查看
      

  12.   

    LZ问题解决了吗? 我也有类似的问题,我用的模拟器2.2的系统,代码也很少,
    java 类里:
         webView = (WebView)findViewById(R.id.webView);
         webView.getSettings().setJavaScriptEnabled(true);
         webView.getSettings().setPluginState(PluginState.ON);
         webView.loadUrl("file:///android_asset/index.html"); html里:
     
    <object width="300" height="200">
    <param name="movie"
    value="http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf"></param>
    <param name="flashvars"
    value="src=http%3A%2F%2Fosmf.org%2Fvideos%2Fcathy2.flv"></param>
    <param name="allowFullScreen" value="true"></param>
    <param name="allowscriptaccess" value="always"></param>
    <embed
    src="http://10.1.1.137:8080/testRed5.swf"
    type="application/x-shockwave-flash" allowscriptaccess="always"
    allowfullscreen="true" width="500" height="300"
    flashvars="src=http%3A%2F%2Fosmf.org%2Fvideos%2Fcathy2.flv">
    </embed>
    </object>
    同样也不行,是因为我用的模拟器?我已经安了一个播放器了,分享一下吧,谢谢了
      

  13.   

    和测试手机有关系(准确说,和手机内置的浏览器有关系)。
    曾经我用Nexus s访问公司网站,发现flush页不能显示。后来换了某款HTC 发现可以
      

  14.   

    我的webView要加载整个纯flash网页,再3.2的平板上,点击flash网页中的网页链接,shouldOverrideUrlLoading()方法居然没有反应,,不知道怎么回事??还有,我在flash网页加载完成前,显示了一张启动动画,然后加载完成就去掉图片,,这样显示其他网页是没问题的,就是显示这个纯flash网页显示不出来,,郁闷啊,,
    有人知道吗?
      

  15.   

    对于本地的文件路径,要加上file:///的前缀来访问
    最近我也在做这个,3.1的平板,10.3插件,也是有一些问题,放不出来。
    在webView上调用object控件的方法无效。打算参考10楼的方法直接把flash写在网页里写死,再试试。
      

  16.   

    最近在3.1机台上测试用的是一个可以点击发生变化的flash,发现可以听见flash播放的声音,如果滑动手指也能听见flash发生变化的声音,但是看不见flash动画。
    有人知道怎么回事吗?
      

  17.   

    http://allenshao.iteye.com/blog/1040935
      

  18.   

    hai 解决了吗?我也遇到了这个问题,
      

  19.   

    3.0以上,需要开启硬件加速,android:hardwareAccelerated="true"
      

  20.   

    播flash首先要在机子上装falsh播放器 。最近也在做webview 播放flash 我用2.2
      

  21.   

    据说 android3.0 以后的系统不支付播放flash的.swf文件了! 很悲剧
      

  22.   

    据说 android3.0 以后的系统不支付播放flash的.swf文件了! 很悲剧2.2以前的版本是可以播放的。
      

  23.   

    据说google把flash给砍掉了啊只是据说
      

  24.   

    现在也遇到flash文件播放不了的问题,请教大家如何播放优酷或者土豆上面的视频?
      

  25.   

    唉,倒是能播放swf文件,但不是所有的都能播放,而且我想要有一个进度条来手动控制播放进度,这样是不是要用到js呢
      

  26.   

    在清单文件中加上这个android:targetSdkVersion="15"可能就行了 你试试
      

  27.   

    或者在activity里加个硬件加速如: <activity 
                android:name=".FlashListActivity"
                android:screenOrientation="landscape"
                android:hardwareAccelerated="true"></activity>