我已经在代码里加了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();
}
}
但是还是不能播放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();
}
}
解决方案 »
- 急求: android怎么对mpg格式视频实现在线播放???
- 有人了解过屏幕方向改变原理么,在源码什么地方处理根据外界环境控制着系统屏幕的方向变化?
- 使用handler仍然出现UI假死,求解?
- 新手求助:uart接口驱动的疑问
- Ophone 更新联系人信息时出错 显示UnSupportedOperation!!!!!
- 谁在官网上下载过Android Studio?是不是需要翻墙才能下?
- 发送HttpGet请求时,URL包含空格怎么办?
- 第三方移动推送平台
- 请教下service到底有什么用
- 如何获取ListView的Item的高度
- activity间怎么传递acitvity或class或content
- 如何新增加一个git工程(求高手指导)
给你代码参考。。很简单的
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>
<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");这个网页显示空白一片
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>
同样也不行,是因为我用的模拟器?我已经安了一个播放器了,分享一下吧,谢谢了
曾经我用Nexus s访问公司网站,发现flush页不能显示。后来换了某款HTC 发现可以
有人知道吗?
最近我也在做这个,3.1的平板,10.3插件,也是有一些问题,放不出来。
在webView上调用object控件的方法无效。打算参考10楼的方法直接把flash写在网页里写死,再试试。
有人知道怎么回事吗?
android:name=".FlashListActivity"
android:screenOrientation="landscape"
android:hardwareAccelerated="true"></activity>