在现在已经集成的基础上,增加一个独立activity的webview,经过测试可行,不过有个问题,就是在这个页面如果调用了拍照或选择照片功能后,原来的集成模式,安卓系统的返回键没有响应了,但其他功能还能正常使用,请问这种做法可取吗?求教。
代码如下:
(1)主程序集成是这样的:
public class DefaultMainActivity extends io.dcloud.PandoraEntry {
。。。。。
}
(2)新增加Activity集成如下:
public class SDKWebViewActivity extends Activity {
boolean doHardAcc = true;
IWebview webview = null;
EntryProxy mEntryProxy = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
//直接获取存在的低层EntryProxy
mEntryProxy = EntryProxy.getInstnace();
mEntryProxy.onCreate(this, savedInstanceState,
SDK.IntegratedMode.WEBVIEW, null);
final FrameLayout rootView = new FrameLayout(this);
setContentView(rootView);
rootView.setBackgroundColor(0xffffffff);
rootView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
webview.onRootViewGlobalLayout(rootView);
}
});
Bundle bd = this.getIntent().getExtras();
String url = bd.getString("url");
String appid = UUID.randomUUID().toString();
// 单页面集成时要加载页面的路径,可以是本地文件路径也可以是网络路径
String localUrl = "file:///android_asset/apps/AppECMS/www/";
String viewUrl = "";
if (!url.startsWith("http://")) {
viewUrl = localUrl + url;
} else {
viewUrl = url;
}
webview = SDK.createWebview(this, viewUrl, appid,
new IWebviewStateListener() {
@Override
public Object onCallBack(int pType, Object pArgs) {
switch (pType) {
case IWebviewStateListener.ON_WEBVIEW_READY:
// 准备完毕之后添加webview到显示父View中,设置排版不显示状态,避免显示webview时,html内容排版错乱问题
((IWebview) pArgs).obtainFrameView()
.obtainMainView()
.setVisibility(View.INVISIBLE);
SDK.attach(rootView, ((IWebview) pArgs));
break;
case IWebviewStateListener.ON_PAGE_STARTED:
// 首页面开始加载事件
break;
case IWebviewStateListener.ON_PROGRESS_CHANGED:
// 首页面加载进度变化
break;
case IWebviewStateListener.ON_PAGE_FINISHED:
// 页面加载完毕,设置显示webview
webview.obtainFrameView().obtainMainView()
.setVisibility(View.VISIBLE);
break;
}
return null;
}
});
final WebView webviewInstance = webview.obtainWebview();
// 添加自定义JS交互对象
webviewInstance.addJavascriptInterface(new EcmsPlusImpl(this),
"EcmsPlus");
// 监听返回键
webviewInstance.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (webviewInstance.canGoBack()) {
webviewInstance.goBack();
return true;
} else {
SDKWebViewActivity.this.finish();
}
}
return false;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return mEntryProxy.onActivityExecute(this,
SysEventType.onCreateOptionMenu, menu);
}
@Override
public void onPause() {
super.onPause();
mEntryProxy.onPause(this);
}
@Override
public void onResume() {
super.onResume();
mEntryProxy.onResume(this);
}
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent.getFlags() != 0x10600000) {// 非点击icon调用activity时才调用newintent事件
mEntryProxy.onNewIntent(this, intent);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
mEntryProxy.destroy(this);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean _ret = mEntryProxy.onActivityExecute(this,
SysEventType.onKeyDown, new Object[] { keyCode, event });
return _ret ? _ret : super.onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
boolean _ret = mEntryProxy.onActivityExecute(this,
SysEventType.onKeyUp, new Object[] { keyCode, event });
return _ret ? _ret : super.onKeyUp(keyCode, event);
}
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
boolean _ret = mEntryProxy.onActivityExecute(this,
SysEventType.onKeyLongPress, new Object[] { keyCode, event });
return _ret ? _ret : super.onKeyLongPress(keyCode, event);
}
public void onConfigurationChanged(Configuration newConfig) {
try {
int temp = this.getResources().getConfiguration().orientation;
if (mEntryProxy != null) {
mEntryProxy.onConfigurationChanged(this, temp);
}
super.onConfigurationChanged(newConfig);
} catch (Exception e) {
e.printStackTrace();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mEntryProxy.onActivityExecute(this, SysEventType.onActivityResult,
new Object[] { requestCode, resultCode, data });
}
}
2 个回复
阿斯蒂 - eeeeeeeeeeeeeeeeeeeeeeeeeeeee
去下载新的sdk,官方说已经修改了bug,我的原因是因为我启用了多个iwebview,所以我在页面结束的时候用:SDK.closewebview(mWebview);清理了一下就可以了
l***@live.com
马克