安卓4.4不能用sd卡.2不能用 chrome 吗

1965人阅读
放弃WebView,使用Crosswalk做富文本编辑器
原文链接:
原文链接:/a/9135
为什么放弃WebView
Android WebView做普通浏览还好,做富文本编辑器,常常会遇到各种奇葩的bug,而且很难修复。尽管Google在版本迭代中不断修复bug,但依旧没法用它来做富文本编辑。
Kitcat的改变
Google为了加强WebView的功能,在Kitcat引入了Chromium内核。但还是存在着编辑的bug。
我所知道的一个bug是:
Kitcat版WebView在删除Html标签时处理不好,例如 &img&标签,就无法删除。点击删除时直接越过此元素,将光标定位在图片前方,对图片不做处理。
当然,这个bug在Android 5.0 修复了。
Lollipop新策略
Although WebView has been based on Chromium since Android 4.4, the Chromium layer is now updatable from Google Play.As new versions of Chromium become available, users can update from Google Play to ensure they get the latest enhancements and bug fixes for
WebView, providing the latest web APIs and bug fixes for apps using WebView on Android 5.0 and higher.
可见在Lollipop里,可以通过GooglePlay来更新Chromium内核。
但是问题来了:
国内容易更新么? 如果不是自动更新,用户会手动更新么?当然GooglePlay是自动更新,那国内手机没有自己市场的厂商呢? Lollipop以前的版本怎么办? Lollipop目前只有很少用户可以更新。
探索新的富文本编辑方案
显然,即便是有了Lollipop的解决方案,但问题依然很多。我们还是需要一个替代方案,来保证我们在所有的Android手机上表现一致。
这个方案就是在应用中集成Chromium。
由于自己编译Chromium的难度较大,于是转而寻找编译好的Chromium库来使用。
需要声明的是:Chromium内核只能在Android 4.0以上才能使用,之后提到的所有Chromium库都只能在4.0以上平台使用。
最初在寻找替代方案的时候,应该是2013年10月左右,找到了两个Chromium库:
这个库封装的较好,但是有一个致命的bug是不能滚动。
README中声明:
Attempting to scroll the view (by swiping a finger across the screen) does not update the displayed image.
However, internally, the view is scrolled.
This can be seen by displaying a stack of buttons and trying to click on the topmost one.
This issue makes ChromeView mostly unusable in production.
注:这个库的README最新声明里面推荐了Crosswalk,作者还是很用心的。
这个库整体稳定,不存在上面的bug。用它作为编辑器差不多一年,没有出现什么问题。
但在今年6、7月的时候,突然间发现在三星新出的几款平板上(搭载了Kitcat)表现为花屏,屏幕上出现了各种颜色的横条,无法进行编辑。其他搭载了Kitcat的手机当时没有发现过什么问题。
这里说一下这个库,自从作者看到Kitcat使用Chromium后,作者就声明不再更新了,其实差不多一年前就已经不更新了。
这个库使用起来比较麻烦,需要自己再进行封装,甚至连onPageFinished都需要自己来做。
可以看到,上面的替代方案,到今年6、7月,实际上已经无法使用。
而且非组织维护的代码,通常都有些不可靠的意味。
于是不得不继续寻找替代方案。终于在Google I/O上看到了希望 —— Crosswalk
Crosswalk入门
上面的链接可以看到Crosswalk的介绍,Crosswalk种种吹牛逼的描述我就不写了。写一下我的使用感受:
不用费力搞什么自己封装了,直接像用WebView一样使用。
在使用android-chromium这个库时,不仅要自己封装API来方便使用,还要操心Chromium的初始化,甚至还需要在清单文件里写一堆关于Chromium的东西,用来帮助Chromium建立单独的进程(Crosswalk只会创建Chromium的线程,不需要独立进程)。Crosswalk由组织维护,比个人维护强多了。 跟随最新的Chromium不断更新,js等不用担心有函数没法使用。而且不断更新过程中,肯定也会修复以前存在的bug,稳定性也是不用担心的。
最新稳定版Crosswalk基于Chromium38编译。
注:此库也可以配合Cordova(PhoneGap)使用。
OK,感受说完,上教程。
集成到应用中
下载zip包,解压后导入。 关联此Library。
在清单文件中写入下列权限
android:name=&android.permission.ACCESS_FINE_LOCATION& /&
android:name=&android.permission.ACCESS_NETWORK_STATE& /&
android:name=&android.permission.ACCESS_WIFI_STATE& /&
android:name=&android.permission.CAMERA& /&
android:name=&android.permission.INTERNET& /&
android:name=&android.permission.MODIFY_AUDIO_SETTINGS& /&
android:name=&android.permission.RECORD_AUDIO& /&
android:name=&android.permission.WAKE_LOCK& /&
android:name=&android.permission.WRITE_EXTERNAL_STORAGE& /&
注:使用过程中,观察Logcat可以看到报需要蓝牙权限,可以不用管它,不添加蓝牙权限可以正常使用。此外,使用XWalkView必须开启硬件加速。
XWalkView needs hardware acceleration to render web pages. As a result, the AndroidManifest.xml of the caller's app must be appended with the attribute &android:hardwareAccelerated& and its value must be set as &true&.
android:hardwareAccelerated : The default value is &true& if you've set either minSdkVersion or targetSdkVersion to &14& otherwise, it's &false&.
在清单文件Application中声明即可。
android:name=&android.app.Application& android:label=&XWalkUsers&
android:hardwareAccelerated=&true&&
Crosswalk中用来替代WebView的控件叫XWalkView。
layout文件写法
和其他自定义控件一样。
android:id=&@+id/activity_main&
xmlns:android=&/apk/res/android&
android:layout_width=&fill_parent&
android:layout_height=&fill_parent&&
代码中使用
重中之重:防止内存泄漏
和其他Android的控件不同,这个类需要监听系统事件。例如:生命周期、intent、Activity result。
控件内置的Web引擎需要获取并处理这些信息。并且当XWalkView 不再需要使用的时候,在onDestroy方法中XWalkView必须显式的调用destroy方法,否则容易造成Web引擎的内存泄漏。
原文如下:
Unlike other Android views, this class has to listen to system events like application life cycle, intents, and activity result. The web engine inside this view need to get and handle them. And the onDestroy() method of XWalkView MUST be called explicitly
when an XWalkView won't be used anymore, otherwise it will cause the memory leak from the native side of the web engine. It's similar to the destroy() method of Android WebView.
这段文字来自XWalkView官方API文档。奇怪的是官方的范例中并没有在意这些事情,直接像WebView一样使用,更没有使用destroy方法。考虑到之前使用android-chromium库也是需要显式调用。这里还是加上,避免内存泄漏。
import android.app.A
import android.os.B
import org.xwalk.core.XWalkV
public class MyActivity extends Activity {
private XWalkView mXWalkV
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mXWalkView = (XWalkView) findViewById(R.id.activity_main);
mXWalkView.load(&http://crosswalk-project.org/&, null);
protected void onPause() {
super.onPause();
if (mXWalkView != null) {
mXWalkView.pauseTimers();
mXWalkView.onHide();
protected void onResume() {
super.onResume();
if (mXWalkView != null) {
mXWalkView.resumeTimers();
mXWalkView.onShow();
protected void onDestroy() {
super.onDestroy();
if (mXWalkView != null) {
mXWalkView.onDestroy();
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (mXWalkView != null) {
mXWalkView.onActivityResult(requestCode, resultCode, data);
protected void onNewIntent(Intent intent) {
if (mXWalkView != null) {
mXWalkView.onNewIntent(intent);
loadUrl去哪了?
上面的代码中其实已经剧透了,使用load方法即可。
mXWalkView.load(&http://crosswalk-project.org/&, null);
// this loads a file from the assets/ directory
mXWalkView.load(&file:///android_asset/index.html&, null);
public void load (String url, String content)
Load a web page/app from a given base URL or a content. If url is null or empty and content is null or empty, then this function will do nothing. If content is not null, load the web page/app from the content. If content is not null and the url is not set,
return &about:blank& ifi calling getUrl(). If content is null, try to load the content from the url. It supports URL schemes like 'http:', 'https:' and 'file:'. It can also load files from Android assets, e.g. ''.
Parameters
url the url for web page/app.
content the content for the web page/app. Could be empty.
WebViewClient?
对应WebView的WebViewClient,XWalkView中有XWalkResourceClient。
mXWalkView.setResourceClient(new XWalkResourceClient(mXWalkView){
public void onLoadFinished(XWalkView view, String url) {
super.onLoadFinished(view, url);
public void onLoadStarted(XWalkView view, String url) {
super.onLoadStarted(view, url);
调用JavaScript
mXWalkView = (XWalkView) findViewById(R.id.activity_main);
XWalkSettings webSettings = mXWalkView.getSettings();
webSettings.setJavaScriptEnabled(true);
mXWalkView.load(&javascript:document.body.contentEditable=&, null);
当然,按照Kitcat引入的方式,使用evaluateJavascript方法也是可以的。(大神们推荐)
JavaScript回调Java
定义js回调接口
public class JsInterface {
public JsInterface() {
@JavascriptInterface
public String sayHello() {
return &Hello World!&;
Caution: If you've set your targetSdkVersion to 17 or higher, you must add the @JavascriptInterface annotation to any method that you want available to your JavaScript (the method must also be public). If you do not provide the annotation, the method is
not accessible by your web page when running on Android 4.2 or higher.From
备注:这里的 @JavaScriptInterface所在的包是
import org.xwalk.core.JavascriptI
XWalkView设置JavaScript可用且绑定对象
mXWalkView = (XWalkView) findViewById(R.id.activity_main);
XWalkSettings webSettings = mXWalkView.getSettings();
webSettings.setJavaScriptEnabled(true);
mXWalkView.addJavascriptInterface(new JsInterface(), &NativeInterface&);
调用html执行JavaScript或直接执行Javascript调用Java
mXWalkView.load(&file:///android_asset/index.html&, null);
index.html源码:
href=&#& onclick=&clicked()&&Say Hello&
function clicked() {
alert(NativeInterface.sayHello());
Kitcat开始,Android提供了和Chrome联调功能。可以很方便的在Chrome中调试WebView中的代码。
Crosswalk使用Chromium内核当然也具备这个功能。
开启调试的语句如下:
XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
对于Crosswalk来说,这个设置是全局的。
使用动画或者设置隐藏可见注意
默认XWalkView不能使用动画,甚至setVisibility也不行。
XWalkView represents an Android view for web apps/pages. Thus most of attributes for Android view are valid for this class. Since it internally uses android.view.SurfaceView for rendering web pages by default, it can't be resized, rotated, transformed and
animated due to the limitations of SurfaceView. Alternatively, if the preference key ANIMATABLE_XWALK_VIEW is set to True, XWalkView can be transformed and animated because TextureView is intentionally used to render web pages for animation support. Besides,
XWalkView won't be rendered if it's invisible.
开启动画模式:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, true);
setContentView(R.layout.animatable_xwview_layout);
public void onDestroy() {
super.onDestroy();
XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, false);
由于设置也像调试一样是全局的,在onDestroy时记得关闭。
暂停JS timer
&!DOCTYPE html&
&A script on this page starts this clock:&
id=&demo&&&
var myVar = setInterval(function(){ myTimer(); }, 1000);
function myTimer()
var d = new Date();
var t = d.toLocaleTimeString();
document.getElementById(&demo&).innerHTML =
XWalkView对应方法:
mButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (mXWalkView != null) {
if (!isPaused) {
mXWalkView.pauseTimers();
isPaused = true;
mButton.setImageResource(android.R.drawable.ic_media_play);
mXWalkView.resumeTimers();
isPaused = false;
mButton.setImageResource(android.R.drawable.ic_media_pause);
这也在防止内存泄漏,监听系统事件示例代码中提到过:
protected void onPause() {
super.onPause();
if (mXWalkView != null) {
mXWalkView.pauseTimers();
mXWalkView.onHide();
protected void onResume() {
super.onResume();
if (mXWalkView != null) {
mXWalkView.resumeTimers();
mXWalkView.onShow();
mPrevButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (mXWalkView != null &&
mXWalkView.getNavigationHistory().canGoBack()) {
mXWalkView.getNavigationHistory().navigate(
XWalkNavigationHistory.Direction.BACKWARD, 1);
XWalkNavigationItem navigationItem = mXWalkView.getNavigationHistory().getCurrentItem();
showNavigationItemInfo(navigationItem);
mNextButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (mXWalkView != null &&
mXWalkView.getNavigationHistory().canGoForward()) {
mXWalkView.getNavigationHistory().navigate(
XWalkNavigationHistory.Direction.FORWARD, 1);
XWalkNavigationItem navigationItem = mXWalkView.getNavigationHistory().getCurrentItem();
showNavigationItemInfo(navigationItem);
private void showNavigationItemInfo(XWalkNavigationItem navigationItem){
url = navigationItem.getUrl();
originalUrl = navigationItem.getOriginalUrl();
title = navigationItem.getTitle();
text1.setText(title);
text2.setText(url);
text3.setText(originalUrl);
自动视频暂停
mXWalkView.load(&http://www.w3.org/2010/05/video/mediaevents.html&, null);
loadAppFromManifest
mXWalkView.loadAppFromManifest(&file:///android_asset/manifest.json&, null);
manifest.json
&name&: &ManifestTest&,
&start_url&: &index.html&,
&description&: &Manifest test&,
&version&: &1.0.0&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:3813次
排名:千里之外
(1)(3)(1)(1)安卓4.4.2谷歌服务套件单刷包_木子软件
安卓4.4.2谷歌服务套件单刷包
当前位置:> > 安卓4.4.2谷歌服务套件单刷包
安卓4.4.2谷歌服务套件单刷包
大小:13.49 M
类别:刷机软件
版本:1.0.0
厂商:enter
浏览次数:0
页面最后更新时间: 11:00
安卓4.4.2谷歌服务套件单刷包相关下载地址表
版本号更新时间下载地址
相关攻略与资讯
谷歌向外界宣布,今年4月份以后的新版安卓Chrome浏览器将不再支持安卓4.0系统,谷歌对此也进行了解释,在安卓4.0系统下的Chrome使用率下跌了30%。而且目前最新的统计数据显示安卓4.0的市场份额只有5.9%。}

我要回帖

更多关于 安卓4.4.2刷机包 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信