android studio 集成文檔
android studio集成方法
1.創(chuàng)建一個android工程
2.通過拷貝添加arr文件到libs
image.png
3.在app文件的build.gradle配置如下
android{
...
defaultConfig{
...
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86"
//輸出指定三種abi體系結(jié)構(gòu)下的so庫
}
...
}
...
repositories {
flatDir {
dirs 'libs'
// aar目錄
}
}
...
dependencies{
...
implementation(name: "enterplorer_library", ext: "aar")
implementation(name: "xwalk_core_library", ext: "aar")
...
}
}
4.Manifest權(quán)限
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
5.項目中的使用
-
使用前請先配置 app/src/main/assets/config.metadata文件
image.png - 內(nèi)容如下
{"companyName": "you company name", "managerServer": "you manager server address", "managerProxy": ""}
以上詳情,請與PM聯(lián)系,并索要相關(guān)信息
5.1初始化SDK
- 在application中初始化SDK
XCloudSDKManager.getInstance().init(this);
- 注意事項:
- 初始化SDK的過程中,需要獲取本機信息,android SDK 23版本或以上,需要權(quán)限.請修改目標(biāo)版本至22,否側(cè)可能初始化失敗.
targetSdkVersion 22
5.2使用
在使用界面,執(zhí)行如下代碼,進行SDK驗證
XCloudSDKManager.getInstance().authRequest(this, new Callback() {
@Override
public void success() {
mLoadingDialog.dismiss();
initTabFragment("目標(biāo)url");
}
@Override
public void error(String errorMsg) {
mLoadingDialog.dismiss();
Toast.makeText(BrowserActivity.this, errorMsg, Toast.LENGTH_SHORT).show();
}
});
- 如上,initTabFragment("url")方法如下
private void initTabFragment(String url) {
TabFragment.Builder builder = new TabFragment.Builder();
// ProxyChangeListener.setProxyConfig("192.168.2.18", 8888, null, new String[]{"oa.yunshipei.com"});
/**
* 加載{@link #url}時設(shè)置cookie實現(xiàn)單點登錄
*/
ArrayList<CookieModel> cookieModelList = new ArrayList<>();
String cookie = CookieManager.getInstance().getCookie(url);cookieModelList.add(new CookieModel(url, cookie));
builder.setCookies(cookieModelList);
/**
* 加載{@link #url}時設(shè)置cookie實現(xiàn)單點登錄
* builder.setCookies()
*
* //給每個加載的url加參數(shù)作為單點登錄
* builder.setUrlTokenSSO()
*
* //設(shè)置proxy,401茶宵,403認(rèn)證信息须肆;在頁面需要做認(rèn)證時可以在此配置認(rèn)證信息矛紫,在頁面需要認(rèn)證時將自動根據(jù)配置信息自動認(rèn)證將不再彈出認(rèn)證對話框
* builder.setHttpAuthorizations()
*
* //設(shè)置全局運行時版本
* builder.setGlobalRuntime()
*/
//設(shè)置webView加載的Url
builder.setUrl(url);
//設(shè)置默認(rèn)是否支持雙webView退疫。具體是否支持請詢問適配開發(fā)工程師鹉动。
builder.setDefault2WebView(false);
//設(shè)置頁面水印
builder.setWaterMark(new WaterMarkConfig.Builder().setShowDateTime(true).setWtmTexts(Arrays.asList("云適配", "適配SDK")).build());
//設(shè)置頁面字體大小
builder.setTextZoom(100);
//文檔預(yù)覽 使用永中文檔轉(zhuǎn)換服務(wù)器進行文檔預(yù)覽
FilePreviewConfig.Builder filePreviewConfigBuilder = new FilePreviewConfig.Builder();
//設(shè)置永中文檔轉(zhuǎn)換服務(wù)器地址
filePreviewConfigBuilder.setDocConvertServer("http://139.217.22.35:8080");
HashMap<String, String> map = new HashMap<>();
map.put("rtf", "0");
map.put("eio", "0");
map.put("uof", "0");
map.put("uos", "0");
map.put("xml", "0");
map.put("txt", "0");
filePreviewConfigBuilder.setDocTypes(map);
/**
//設(shè)置是否自行處理文檔轉(zhuǎn)換后的url(默認(rèn)狀態(tài)為false,使用SDK內(nèi)部默認(rèn)的文檔在線處理邏輯)
filePreviewConfigBuilder.setExternalPreview(false);
//在訪問永中轉(zhuǎn)換服務(wù)器時如果需要通過代理訪問爪喘,請設(shè)置代理服務(wù)信息
filePreviewConfigBuilder.setFilePreviewServerProxy("xxx.xxx.xxx.xxxx", 8787);
**/
builder.setFilePreview(filePreviewConfigBuilder.build());
/**
* TabFragment是用來顯示webView窗口的重要組件颜曾。tabFragment 必須在{@link XCloudSDKManager#authRequest(Context, Callback)}
* 請求成功回調(diào)到{@link Callback#success()}后才可以創(chuàng)建對象并attach到View中。
*/
mTabFragment = builder.build();
ArrayList<HttpAuthModel> httpAuthModels = new ArrayList<>();
httpAuthModels.add(new HttpAuthModel("host","name","psd"));
builder.setHttpAuthorizations(httpAuthModels);
//webView 注入native method
JavascriptExample javascriptExample = new JavascriptExample(this, mTabFragment);
mTabFragment.addJavascriptInterface(javascriptExample, "APIExample");
getSupportFragmentManager().beginTransaction().replace(R.id.fl_browser_tab, mTabFragment, mTabFragment.getClass().getName()).commit();
/**
* webView(crosswalk)文件下載監(jiān)聽設(shè)置
*/
// mTabFragment.setEnterDownloadListener(new EnterDownloadListener() {
// @Override
// public void onDownload(String fromUrl, XDownloadModel xDownloadModel) {
// /**
// * 實現(xiàn)具體的下載邏輯...
// */
// }
// });
/**
* 日志上傳
*/
YspLogUtils.uploadLog("小明", new Callback() {
@Override
public void success() {
}
@Override
public void error(String errorMsg) {
}
});
//sdk擴展功能
setextralEvent(mTabFragment);
mTabFragment.setOnFragmentInteractionListener(new TabFragment.OnFragmentInteractionListener() {
@Override
public void backTop() {
finish();
}
@Override
public void webViewUrlChanged(String s) {
}
@Override
public void kingGridFile(String s) {
}
private int retry = 3;
@Override
public boolean onReceivedHttpAuthRequest(XWalkView xWalkView, XWalkHttpAuthHandler xWalkHttpAuthHandler, final String host, String s1) {
String u = YspSharePreUtil.getInstance(BrowserActivity.this).getLocalStorage("YSP_" + host + "_username");
String p = YspSharePreUtil.getInstance(BrowserActivity.this).getLocalStorage("YSP_" + host + "_password");
if (retry-- > 0) {
xWalkHttpAuthHandler.proceed(u, p);
return true;
}
final XWalkHttpAuthHandler haHandler = xWalkHttpAuthHandler;
Context context = xWalkView.getContext();
LinearLayout layout = new LinearLayout(context);
final EditText userNameEditText = new EditText(context);
final EditText passwordEditText = new EditText(context);
layout.setOrientation(LinearLayout.VERTICAL);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
layout.setPaddingRelative(10, 0, 10, 20);
} else {
layout.setPadding(10, 0, 10, 20);
}
userNameEditText.setHint(R.string.http_auth_user_name);
passwordEditText.setHint(R.string.http_auth_password);
passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
layout.addView(userNameEditText);
layout.addView(passwordEditText);
AlertDialog.Builder httpAuthDialog = new AlertDialog.Builder(BrowserActivity.this);
httpAuthDialog.setTitle(R.string.http_auth_title)
.setView(layout)
.setCancelable(false)
.setPositiveButton(R.string.http_auth_log_in,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
String userName = userNameEditText.getText().toString();
String password = passwordEditText.getText().toString();
haHandler.proceed(userName, password);
YspSharePreUtil.getInstance(BrowserActivity.this).setLocalStorage("YSP_" + host + "_username", userName);
YspSharePreUtil.getInstance(BrowserActivity.this).setLocalStorage("YSP_" + host + "_password", password);
dialog.dismiss();
}
}).setNegativeButton(android.R.string.cancel, null)
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
haHandler.cancel();
}
}).create().show();
return true;
}
@Override
public void tabProgressChanged(int i) {
}
@Override
public void backPreWebView(boolean b) {
}
@Override
public boolean shouldHandleNoMatcherUrlFromOpenWindow(String s) {
return false;
}
@Override
public boolean shouldInterceptWebViewShouldOverrideUrlLoadingMethod(XWalkView xWalkView, String s) {
return false;
}
// 密碼代填
@Override
public AutoLoginModel getAutoLoginModel(String s) {
if (s.contains("http://oa.yunshipei.com/")) {
return new AutoLoginModel("http://*[@id=\"userId\"]", "http://*[@id=\"userPwd\"]", "http://*[@id=\"tableheight\"]/tbody/tr[3]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td[3]/img", "test1", "123456");
}
return null;
}
/**
* 永中文檔在線預(yù)覽開發(fā)者自行處理秉剑。
* @param s 文檔轉(zhuǎn)換后的地址泛豪;如:http://192.xxxx.xxx.xxx/prexxxx.html
*/
@Override
public void filePreviewConvertResult(String s) {
/**
* 如果在設(shè)置永中文檔轉(zhuǎn)換服務(wù)器轉(zhuǎn)化后將url暴露出來供開發(fā)者自己處理。
* filePreviewConfigBuilder.setExternalPreview(true);
* 此時需要開發(fā)者自己處理相關(guān)邏輯
*/
}
/**
* 自定義WebView(crosswalk)適配頁面加載的loading樣式
* @param s 加載適配頁面?zhèn)鬟f過來的提示信息侦鹏;
* @return true標(biāo)示使用自定義的loading诡曙;false標(biāo)示使用sdk默認(rèn)loading
*/
@Override
public boolean showAdapterLoading(String s) {
if(webLoadingDialog != null) {
webLoadingDialog.show();
//使用自定義loading樣式時,返回true
return true;
}
//使用默認(rèn)loading則返回false
return false;
}
/**
* 關(guān)閉自定義適配頁面加載loading
* 此方法必須和{@link #showAdapterLoading(String)}同時實現(xiàn)
* @return true標(biāo)示關(guān)閉自定義的loading略水;false標(biāo)示關(guān)閉sdk默認(rèn)loading
*/
@Override
public boolean hideAdapterLoading() {
if(webLoadingDialog != null && webLoadingDialog.isShowing()) {
webLoadingDialog.cancel();
//關(guān)閉自定義loading樣式時价卤,返回true
return true;
}
//關(guān)閉默認(rèn)的loading,直接返回false
return false;
}
@Override
public String getSecurityGatewayKey() {
return null;
}
});
}
5.3 全部代碼如下
package com.example.app;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.CookieManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.example.model.JavascriptExample;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import com.yunshipei.core.common.Callback;
import com.yunshipei.core.common.PageLocationListener;
import com.yunshipei.core.common.QRCodeDecoderListener;
import com.yunshipei.core.common.bridge.inter.JsCallback;
import com.yunshipei.core.manager.XCloudSDKManager;
import com.yunshipei.core.model.AutoLoginModel;
import com.yunshipei.core.model.CookieModel;
import com.yunshipei.core.model.FilePreviewConfig;
import com.yunshipei.core.model.HttpAuthModel;
import com.yunshipei.core.model.WaterMarkConfig;
import com.yunshipei.core.ui.TabFragment;
import com.yunshipei.core.utils.YspLogUtils;
import com.yunshipei.core.utils.YspSharePreUtil;
import org.json.JSONException;
import org.json.JSONObject;
import org.xwalk.core.XWalkHttpAuthHandler;
import org.xwalk.core.XWalkView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class BrowserActivity extends AppCompatActivity {
private static final String TAG = BrowserActivity.class.getSimpleName();
public static final String EXTRA_URL = "adapter_url";
public static final String EXTRA_TITLE = "adapter_title";
public static final String EXTRA_IDS = "adapters_ids";
private TabFragment mTabFragment;
private LoadingDialog webLoadingDialog = null;
private AMapLocationClient aMapLocationClient = null; //高德定位
private AMapLocationClientOption option = null;
private JsCallback scanQRCodeJsCallback = null; //js二維碼掃描結(jié)果回調(diào)
@BindView(R.id.tv_title)
protected TextView tvTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browser);
ButterKnife.bind(this);
tvTitle.setText(getIntent().getStringExtra(EXTRA_TITLE));
final String url = getIntent().getStringExtra(EXTRA_URL);
final LoadingDialog mLoadingDialog = new LoadingDialog(this);
mLoadingDialog.setTitle("加載中渊涝,請稍候...");
mLoadingDialog.show();
if (savedInstanceState != null) {
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentByTag(TabFragment.class.getName());
if (fragment != null) {
fm.beginTransaction().remove(fragment).commit();
fm.executePendingTransactions();
}
}
// XCloudSDKManager.getInstance().shouldReAuthRequest(); 有重新登錄需求的時候需要開啟
XCloudSDKManager.getInstance().authRequest(this, new Callback() {
@Override
public void success() {
mLoadingDialog.dismiss();
initTabFragment("目標(biāo)url");
}
@Override
public void error(String errorMsg) {
mLoadingDialog.dismiss();
Toast.makeText(BrowserActivity.this, errorMsg, Toast.LENGTH_SHORT).show();
}
});
}
@Override
protected void onResumeFragments() {
super.onResumeFragments();
if (webLoadingDialog == null) {
webLoadingDialog = new LoadingDialog(this);
webLoadingDialog.setTitle("頁面加載中...");
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//js二維碼掃描結(jié)果回傳給webpage
IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (intentResult != null && !TextUtils.isEmpty(intentResult.getContents())) {
if (scanQRCodeJsCallback != null)
scanQRCodeJsCallback.onCallback(intentResult.getContents());
}
super.onActivityResult(requestCode, resultCode, data);
}
private void initTabFragment(String url) {
TabFragment.Builder builder = new TabFragment.Builder();
// ProxyChangeListener.setProxyConfig("192.168.2.18", 8888, null, new String[]{"oa.yunshipei.com"});
/**
* 加載{@link #url}時設(shè)置cookie實現(xiàn)單點登錄
*/
ArrayList<CookieModel> cookieModelList = new ArrayList<>();
String cookie = CookieManager.getInstance().getCookie(url);cookieModelList.add(new CookieModel(url, cookie));
builder.setCookies(cookieModelList);
/**
* 加載{@link #url}時設(shè)置cookie實現(xiàn)單點登錄
* builder.setCookies()
*
* //給每個加載的url加參數(shù)作為單點登錄
* builder.setUrlTokenSSO()
*
* //設(shè)置proxy慎璧,401,403認(rèn)證信息跨释;在頁面需要做認(rèn)證時可以在此配置認(rèn)證信息胸私,在頁面需要認(rèn)證時將自動根據(jù)配置信息自動認(rèn)證將不再彈出認(rèn)證對話框
* builder.setHttpAuthorizations()
*
* //設(shè)置全局運行時版本
* builder.setGlobalRuntime()
*/
//設(shè)置webView加載的Url
builder.setUrl(url);
//設(shè)置默認(rèn)是否支持雙webView。具體是否支持請詢問適配開發(fā)工程師鳖谈。
builder.setDefault2WebView(false);
//設(shè)置頁面水印
builder.setWaterMark(new WaterMarkConfig.Builder().setShowDateTime(true).setWtmTexts(Arrays.asList("云適配", "適配SDK")).build());
//設(shè)置頁面字體大小
builder.setTextZoom(100);
//文檔預(yù)覽 使用永中文檔轉(zhuǎn)換服務(wù)器進行文檔預(yù)覽
FilePreviewConfig.Builder filePreviewConfigBuilder = new FilePreviewConfig.Builder();
//設(shè)置永中文檔轉(zhuǎn)換服務(wù)器地址
filePreviewConfigBuilder.setDocConvertServer("http://139.217.22.35:8080");
HashMap<String, String> map = new HashMap<>();
map.put("rtf", "0");
map.put("eio", "0");
map.put("uof", "0");
map.put("uos", "0");
map.put("xml", "0");
map.put("txt", "0");
filePreviewConfigBuilder.setDocTypes(map);
/**
//設(shè)置是否自行處理文檔轉(zhuǎn)換后的url(默認(rèn)狀態(tài)為false岁疼,使用SDK內(nèi)部默認(rèn)的文檔在線處理邏輯)
filePreviewConfigBuilder.setExternalPreview(false);
//在訪問永中轉(zhuǎn)換服務(wù)器時如果需要通過代理訪問,請設(shè)置代理服務(wù)信息
filePreviewConfigBuilder.setFilePreviewServerProxy("xxx.xxx.xxx.xxxx", 8787);
**/
builder.setFilePreview(filePreviewConfigBuilder.build());
/**
* TabFragment是用來顯示webView窗口的重要組件缆娃。tabFragment 必須在{@link XCloudSDKManager#authRequest(Context, Callback)}
* 請求成功回調(diào)到{@link Callback#success()}后才可以創(chuàng)建對象并attach到View中捷绒。
*/
mTabFragment = builder.build();
ArrayList<HttpAuthModel> httpAuthModels = new ArrayList<>();
httpAuthModels.add(new HttpAuthModel("host","name","psd"));
builder.setHttpAuthorizations(httpAuthModels);
//webView 注入native method
JavascriptExample javascriptExample = new JavascriptExample(this, mTabFragment);
mTabFragment.addJavascriptInterface(javascriptExample, "APIExample");
getSupportFragmentManager().beginTransaction().replace(R.id.fl_browser_tab, mTabFragment, mTabFragment.getClass().getName()).commit();
/**
* webView(crosswalk)文件下載監(jiān)聽設(shè)置
*/
// mTabFragment.setEnterDownloadListener(new EnterDownloadListener() {
// @Override
// public void onDownload(String fromUrl, XDownloadModel xDownloadModel) {
// /**
// * 實現(xiàn)具體的下載邏輯...
// */
// }
// });
/**
* 日志上傳
*/
YspLogUtils.uploadLog("小明", new Callback() {
@Override
public void success() {
}
@Override
public void error(String errorMsg) {
}
});
//sdk擴展功能
setextralEvent(mTabFragment);
mTabFragment.setOnFragmentInteractionListener(new TabFragment.OnFragmentInteractionListener() {
@Override
public void backTop() {
finish();
}
@Override
public void webViewUrlChanged(String s) {
}
@Override
public void kingGridFile(String s) {
}
private int retry = 3;
@Override
public boolean onReceivedHttpAuthRequest(XWalkView xWalkView, XWalkHttpAuthHandler xWalkHttpAuthHandler, final String host, String s1) {
String u = YspSharePreUtil.getInstance(BrowserActivity.this).getLocalStorage("YSP_" + host + "_username");
String p = YspSharePreUtil.getInstance(BrowserActivity.this).getLocalStorage("YSP_" + host + "_password");
if (retry-- > 0) {
xWalkHttpAuthHandler.proceed(u, p);
return true;
}
final XWalkHttpAuthHandler haHandler = xWalkHttpAuthHandler;
Context context = xWalkView.getContext();
LinearLayout layout = new LinearLayout(context);
final EditText userNameEditText = new EditText(context);
final EditText passwordEditText = new EditText(context);
layout.setOrientation(LinearLayout.VERTICAL);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
layout.setPaddingRelative(10, 0, 10, 20);
} else {
layout.setPadding(10, 0, 10, 20);
}
userNameEditText.setHint(R.string.http_auth_user_name);
passwordEditText.setHint(R.string.http_auth_password);
passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
layout.addView(userNameEditText);
layout.addView(passwordEditText);
AlertDialog.Builder httpAuthDialog = new AlertDialog.Builder(BrowserActivity.this);
httpAuthDialog.setTitle(R.string.http_auth_title)
.setView(layout)
.setCancelable(false)
.setPositiveButton(R.string.http_auth_log_in,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
String userName = userNameEditText.getText().toString();
String password = passwordEditText.getText().toString();
haHandler.proceed(userName, password);
YspSharePreUtil.getInstance(BrowserActivity.this).setLocalStorage("YSP_" + host + "_username", userName);
YspSharePreUtil.getInstance(BrowserActivity.this).setLocalStorage("YSP_" + host + "_password", password);
dialog.dismiss();
}
}).setNegativeButton(android.R.string.cancel, null)
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
haHandler.cancel();
}
}).create().show();
return true;
}
@Override
public void tabProgressChanged(int i) {
}
@Override
public void backPreWebView(boolean b) {
}
@Override
public boolean shouldHandleNoMatcherUrlFromOpenWindow(String s) {
return false;
}
@Override
public boolean shouldInterceptWebViewShouldOverrideUrlLoadingMethod(XWalkView xWalkView, String s) {
return false;
}
// 密碼代填
@Override
public AutoLoginModel getAutoLoginModel(String s) {
if (s.contains("http://oa.yunshipei.com/")) {
return new AutoLoginModel("http://*[@id=\"userId\"]", "http://*[@id=\"userPwd\"]", "http://*[@id=\"tableheight\"]/tbody/tr[3]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td[3]/img", "test1", "123456");
}
return null;
}
/**
* 永中文檔在線預(yù)覽開發(fā)者自行處理。
* @param s 文檔轉(zhuǎn)換后的地址贯要;如:http://192.xxxx.xxx.xxx/prexxxx.html
*/
@Override
public void filePreviewConvertResult(String s) {
/**
* 如果在設(shè)置永中文檔轉(zhuǎn)換服務(wù)器轉(zhuǎn)化后將url暴露出來供開發(fā)者自己處理暖侨。
* filePreviewConfigBuilder.setExternalPreview(true);
* 此時需要開發(fā)者自己處理相關(guān)邏輯
*/
}
/**
* 自定義WebView(crosswalk)適配頁面加載的loading樣式
* @param s 加載適配頁面?zhèn)鬟f過來的提示信息;
* @return true標(biāo)示使用自定義的loading郭毕;false標(biāo)示使用sdk默認(rèn)loading
*/
@Override
public boolean showAdapterLoading(String s) {
if(webLoadingDialog != null) {
webLoadingDialog.show();
//使用自定義loading樣式時它碎,返回true
return true;
}
//使用默認(rèn)loading則返回false
return false;
}
/**
* 關(guān)閉自定義適配頁面加載loading
* 此方法必須和{@link #showAdapterLoading(String)}同時實現(xiàn)
* @return true標(biāo)示關(guān)閉自定義的loading;false標(biāo)示關(guān)閉sdk默認(rèn)loading
*/
@Override
public boolean hideAdapterLoading() {
if(webLoadingDialog != null && webLoadingDialog.isShowing()) {
webLoadingDialog.cancel();
//關(guān)閉自定義loading樣式時显押,返回true
return true;
}
//關(guān)閉默認(rèn)的loading扳肛,直接返回false
return false;
}
@Override
public String getSecurityGatewayKey() {
return null;
}
});
}
@OnClick({R.id.iv_close, R.id.iv_refresh})
protected void onClickEvent(View view) {
switch (view.getId()) {
case R.id.iv_close:
finish();
break;
case R.id.iv_refresh:
if (mTabFragment != null) {
mTabFragment.refresh();
}
break;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && mTabFragment != null) {
//適配頁面的返回邏輯
mTabFragment.onTabBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mTabFragment != null) {
mTabFragment.release();
}
}
/**
* ----------------------------------------------
* 這部分功能是sdk的相關(guān)擴展功能,如果不需要無需關(guān)注
* 如果需要使用相關(guān)方法可以根據(jù)具體需求具體實現(xiàn)
* 一下實現(xiàn)僅為接口調(diào)用方法展示
*
* @param tabFragment
*/
private void setextralEvent(TabFragment tabFragment) {
if (tabFragment == null) {
Log.d(TAG, "tabFragment 不能為 null 乘碑!");
return;
}
/**
* 設(shè)置網(wǎng)頁調(diào)取二維碼掃描事件的監(jiān)聽
*/
tabFragment.setQrCodeDecoderListener(new QRCodeDecoderListener() {
@Override
public void scanQRCode(JsCallback jsCallback) {
scanQRCodeJsCallback = jsCallback;
new IntentIntegrator(BrowserActivity.this).initiateScan();
}
});
/**
* 設(shè)置網(wǎng)頁獲取位置信息的監(jiān)聽
*/
tabFragment.setPageLocationListener(pageLocationListener);
}
private YSPPageLocationListener pageLocationListener = new YSPPageLocationListener();
class YSPPageLocationListener implements PageLocationListener {
private JsCallback jsCallback;
@Override
public void locationBegin(final JsCallback jsCallback) {
this.jsCallback = jsCallback;
if (ActivityCompat.checkSelfPermission(BrowserActivity.this, "android.permission.ACCESS_COARSE_LOCATION")
!= PackageManager.PERMISSION_GRANTED){
Toast.makeText(getApplicationContext(),"沒有權(quán)限,請手動開啟定位權(quán)限", Toast.LENGTH_SHORT).show();
// 申請一個(或多個)權(quán)限塔次,并提供用于回調(diào)返回的獲取碼(用戶定義)
ActivityCompat.requestPermissions(BrowserActivity.this,new String[]{"android.permission.ACCESS_COARSE_LOCATION"}, 100);
}else{
System.out.println("定位開始O爬摺?恪!P髋住!5缳鳌4甭搿!<夥伞V⒏薄!UU晗场!>诿鳌辕坝!");
doLocation();
}
}
public void doLocation() {
if (aMapLocationClient == null)
aMapLocationClient = new AMapLocationClient(BrowserActivity.this);
if (option == null)
option = getDefaultOption();
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
aMapLocationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
//定位成功
if (aMapLocation != null && aMapLocation.getErrorCode() == 0) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("longitude", aMapLocation.getLongitude());
jsonObject.put("latitude", aMapLocation.getLatitude());
jsonObject.put("address", aMapLocation.getAddress());
} catch (JSONException e) {
e.printStackTrace();
}
jsCallback.onCallback(jsonObject.toString());
} else {
//定位失敗
StringBuffer sb = new StringBuffer();
sb.append("定位失敗" + "\n");
sb.append("錯誤碼:" + aMapLocation.getErrorCode() + "\n");
sb.append("錯誤信息:" + aMapLocation.getErrorInfo() + "\n");
sb.append("錯誤描述:" + aMapLocation.getLocationDetail() + "\n");
jsCallback.onCallback(sb.toString() + "");
}
stopLocation();
destroyLocation();
}
});
aMapLocationClient.setLocationOption(option);
aMapLocationClient.startLocation();
}
};
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
// requestCode即所聲明的權(quán)限獲取碼,在checkSelfPermission時傳入
case 100:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// 獲取到權(quán)限荐健,作相應(yīng)處理(調(diào)用定位SDK應(yīng)當(dāng)確保相關(guān)權(quán)限均被授權(quán)酱畅,否則可能引起定位失敗)
pageLocationListener.doLocation();
} else {
// 沒有獲取到權(quán)限江场,做特殊處理
Toast.makeText(getApplicationContext(), "獲取位置權(quán)限失敗圣贸,請手動開啟", Toast.LENGTH_SHORT).show();
}
break;
default:
break;
}
}
/**
* 定位配置
*
* @return
*/
private AMapLocationClientOption getDefaultOption() {
AMapLocationClientOption mOption = new AMapLocationClientOption();
mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可選,設(shè)置定位模式扛稽,可選的模式有高精度、僅設(shè)備滑负、僅網(wǎng)絡(luò)在张。默認(rèn)為高精度模式
mOption.setGpsFirst(false);//可選,設(shè)置是否gps優(yōu)先矮慕,只在高精度模式下有效帮匾。默認(rèn)關(guān)閉
mOption.setHttpTimeOut(30000);//可選,設(shè)置網(wǎng)絡(luò)請求超時時間痴鳄。默認(rèn)為30秒瘟斜。在僅設(shè)備模式下無效
mOption.setInterval(2000);//可選,設(shè)置定位間隔痪寻。默認(rèn)為2秒
mOption.setNeedAddress(true);//可選螺句,設(shè)置是否返回逆地理地址信息。默認(rèn)是true
mOption.setOnceLocation(false);//可選橡类,設(shè)置是否單次定位蛇尚。默認(rèn)是false
mOption.setOnceLocationLatest(false);//可選,設(shè)置是否等待wifi刷新顾画,默認(rèn)為false.如果設(shè)置為true,會自動變?yōu)閱未味ㄎ蝗〗伲掷m(xù)定位時不要使用
AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);//可選匆笤, 設(shè)置網(wǎng)絡(luò)請求的協(xié)議∑仔埃可選HTTP或者HTTPS炮捧。默認(rèn)為HTTP
mOption.setSensorEnable(false);//可選,設(shè)置是否使用傳感器惦银。默認(rèn)是false
mOption.setWifiScan(true); //可選咆课,設(shè)置是否開啟wifi掃描。默認(rèn)為true璧函,如果設(shè)置為false會同時停止主動刷新傀蚌,停止以后完全依賴于系統(tǒng)刷新,定位位置可能存在誤差
mOption.setLocationCacheEnable(true); //可選蘸吓,設(shè)置是否使用緩存定位善炫,默認(rèn)為true
return mOption;
}
/**
* 停止定位
*/
private void stopLocation() {
if (aMapLocationClient != null)
aMapLocationClient.stopLocation();
}
/**
* 銷毀定位
*/
private void destroyLocation() {
if (aMapLocationClient != null)
aMapLocationClient.onDestroy();
aMapLocationClient = null;
}
}
- 請注意相機/相冊等回調(diào)
- 請參考書寫物理返回鍵攔截方法