我尝试加载从资产的文件夹中的SWF文件到一个web视图,但我没能显示出来。
下面是code:
包com.androidpeople.view;
进口android.app.Activity;
进口android.os.Bundle;
进口android.webkit.WebView;
公共类WebViewExample延伸活动{
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
字符串的HTML =
<对象的宽度= \550 \高度= \400 \>< PARAM NAME = \电影\价值= \文件:///android_asset/co.swf \><嵌入SRC = \文件:///android_asset/co.swf \WIDTH = \550 \高度= \400 \>< /嵌入>< /对象>;
字符串MIMETYPE =text / html的;
字符串编码=UTF-8;
;
的WebView WV =(web视图)findViewById(R.id.webview);
wv.getSettings()setJavaScriptEnabled(真)。
//wv.getSettings().setPluginsEnabled(true);
wv.loadDataWithBaseURL(空,HTML,MIMETYPE,编码,);
wv.setWebViewClient(新HelloWebViewClient());
}
}
包com.androidpeople.view;
进口android.webkit.WebView;
进口android.webkit.WebViewClient;
公共类HelloWebViewClient扩展WebViewClient {
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
view.loadUrl(URL);
返回true;
}
}
清单:
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.androidpeople.view
安卓版code =1
机器人:VERSIONNAME =1.0>
<应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>
<活动机器人:WebViewExampleNAME =
机器人:标签=@字符串/ APP_NAME>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
<使用-SDK安卓的minSdkVersion =5/>
<使用-权限的Android:名称=android.permission.INTERNET对>< /使用-许可>
< /舱单>
现在我有一个新的错误:
六月6日至30日:17:35.207:ERROR / MetadataRetrieverClient(33):未能提取的专辑封面
解决方案
请使用以下code
字符串的HTML =
<对象的宽度= \550 \高度= \400 \>< PARAM NAME = \电影\价值= \文件:///android_asset/co.swf \><嵌入SRC = \文件:///android_asset/co.swf \WIDTH = \550 \高度= \400 \>< /嵌入>< /对象>;
字符串MIMETYPE =text / html的;
字符串编码=UTF-8;
wv.loadDataWithBaseURL(空,HTML,MIMETYPE,编码,);
冷藏这个链接
I try to load a .swf file from assets folder to a webview, but I am not able to display it.
Here is the code:
package com.androidpeople.view;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewExample extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String html =
"<object width=\"550\" height=\"400\"> <param name=\"movie\" value=\"file:///android_asset/co.swf\"> <embed src=\"file:///android_asset/co.swf\" width=\"550\" height=\"400\"> </embed> </object>";
String mimeType = "text/html";
String encoding = "utf-8";
;
WebView wv=(WebView) findViewById(R.id.webview);
wv.getSettings().setJavaScriptEnabled(true);
//wv.getSettings().setPluginsEnabled(true);
wv.loadDataWithBaseURL("null", html, mimeType, encoding, "");
wv.setWebViewClient(new HelloWebViewClient());
}
}
package com.androidpeople.view;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidpeople.view"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".WebViewExample"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="5" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Now I got a new error:
06-30 06:17:35.207: ERROR/MetadataRetrieverClient(33): failed to extract an album art
解决方案
Please used below code
String html =
"<object width=\"550\" height=\"400\"> <param name=\"movie\" value=\"file:///android_asset/co.swf\"> <embed src=\"file:///android_asset/co.swf\" width=\"550\" height=\"400\"> </embed> </object>";
String mimeType = "text/html";
String encoding = "utf-8";
wv.loadDataWithBaseURL("null", html, mimeType, encoding, "");
Reefer this link
上一篇:如何显示使用地图API地址的位置?位置、地址、地图、API
下一篇:Proguard的及XStream与omitField()在AndroidXStream、Proguard、Android、omitField