博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
u3d内嵌H5游戏 设置cookie
阅读量:5284 次
发布时间:2019-06-14

本文共 7643 字,大约阅读时间需要 25 分钟。

Intent intent1 = getIntent();         Log.d("SS", "onCreate: ");         String data = intent1.getStringExtra("cookies");         JSONObject result = null;         try {
result = new JSONObject(data); String id = result.getString("id"); if (id.equals("289")){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } catch(JSONException e) {
} webView = (WebView)findViewById(R.id.webView); WebSettings webSet = webView.getSettings(); webSet.setJavaScriptEnabled(true); webSet.setAllowFileAccess(true); // 自适应屏幕 webSet.setUseWideViewPort(true); webSet.setLoadWithOverviewMode(true);//设置全屏 webSet.setDomStorageEnabled(true); //声音 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
webView.getSettings().setMediaPlaybackRequiresUserGesture(false); } webSet.setDefaultTextEncodingName("UTF-8"); webSet.setJavaScriptEnabled(true); webSet.setJavaScriptCanOpenWindowsAutomatically(true); webSet.setAllowFileAccess(true); webSet.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSet.setSupportZoom(false); webSet.setBuiltInZoomControls(false); webSet.setUseWideViewPort(true); webSet.setSupportMultipleWindows(true);//支持多标签窗口 webSet.setLoadWithOverviewMode(true); webSet.setAppCacheEnabled(true); webSet.setDatabaseEnabled(true); webSet.setDomStorageEnabled(true); webSet.setGeolocationEnabled(true); webSet.setCacheMode(WebSettings.LOAD_DEFAULT); webSet.setAllowFileAccessFromFileURLs(true); webSet.setUserAgentString(webSet.getUserAgentString() + "35wd");//3500游戏微包专用 webSet.setSaveFormData(true); LoadUrl(); webView.loadUrl(gameUrl); webView.setWebViewClient(new WebViewClient(){
// @Override // public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// String url = request.getUrl().toString(); // LoadUrl(); // view.loadUrl(url); // } // return super.shouldOverrideUrlLoading(view, request); // } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains("alipays://platformapi")){//针对阿里网页支付特殊处理 boolean visit = checkAliPayInstalled(H5Activity.this); if(visit){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } } else if(url.contains("weixin://wap/pay?")) {//针对微信支付特殊处理 Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url)); startActivity(intent); return true; } else {
view.loadUrl(url); } // LoadUrl(); // view.loadUrl(url); return super.shouldOverrideUrlLoading(view, url); } @Override public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url); } }); } //判断是否安装支付宝app public boolean checkAliPayInstalled(Context context) {
Uri uri = Uri.parse("alipays://platformapi/startApp"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); ComponentName componentName = intent.resolveActivity(context.getPackageManager()); return componentName != null; } void LoadUrl() {
Intent intent = getIntent(); String data = intent.getStringExtra("cookies"); Log.e("SSSSS", data); JSONObject result = null; try {
result = new JSONObject(data); gameUrl = result.getString("game_url"); JSONObject scoreObj = (JSONObject) result.get("cookie");//对方平台需要的参数 可以免微信登录 String author = scoreObj.getString("value"); String domain = scoreObj.getString("domain"); String expires = scoreObj.getString("expires"); String path = scoreObj.getString("path"); Log.e("author",author); Log.e("expires",expires); Log.e("domain",domain); Log.e("path",path); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(H5Activity.this); } CookieManager cookieManager = CookieManager.getInstance(); long l = System.currentTimeMillis() + Long.valueOf(expires); Date date = new Date(l); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); String format1 = format.format(date); Log.e("format1",format1); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
cookieManager.setAcceptCookie(true); cookieManager.removeSessionCookie(); cookieManager.setCookie(domain, String.format("author=%s",author)); cookieManager.setCookie(domain, String.format("expires=%s",format1)); cookieManager.setCookie(domain, String.format("domain=%s",domain)); cookieManager.setCookie(domain, String.format("path=%s",path)); CookieSyncManager.getInstance().sync(); } else {
cookieManager.removeSessionCookies(null); cookieManager.setAcceptCookie(true); cookieManager.setAcceptThirdPartyCookies(webView, true); cookieManager.setCookie(domain, String.format("author=%s",author));//重点是这块 多个cookie值 需要一个一个设置 不能一次设置 cookieManager.setCookie(domain, String.format("expires=%s",format1)); cookieManager.setCookie(domain, String.format("domain=%s",domain)); cookieManager.setCookie(domain, String.format("path=%s",path)); cookieManager.flush(); } String newCookie = cookieManager.getCookie(".3500.com"); Log.e("sdsd", newCookie); } catch (JSONException e) {
e.printStackTrace(); } } @Override protected void onPause() {
super.onPause(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
webView.onPause(); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// if (webView.canGoBack()) {
// webView.goBack(); // } else {
// H5Activity.this.finish(); // } H5Activity.this.finish(); return true; } return super.onKeyDown(keyCode, event); } protected void onDestroy() {
// 销毁 WebView if (webView != null) {
webView.destroy(); webView = null; } super.onDestroy(); } @Override protected void onResume() {
super.onResume(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
webView.onResume(); } }

转载于:https://www.cnblogs.com/U-tansuo/p/u3d_H5_cookie.html

你可能感兴趣的文章
MetaWeblog API Test
查看>>
c# 文件笔记
查看>>
类和结构
查看>>
心得25--JDK新特性9-泛型1-加深介绍
查看>>
安装NVIDIA驱动时禁用自带nouveau驱动
查看>>
HDU-1255 覆盖的面积 (扫描线)
查看>>
Java 中 静态方法与非静态方法的区别
查看>>
Jenkins+ProGet+Windows Batch搭建全自动的内部包(NuGet)打包和推送及管理平台
查看>>
线程池的概念
查看>>
Java 序列化
查看>>
Java 时间处理实例
查看>>
Java 多线程编程
查看>>
Java 数组实例
查看>>
mysql启动过程
查看>>
2017前端面试题总结
查看>>
SWIFT国际资金清算系统
查看>>
站立会议第四天
查看>>
利用AMPScript获取Uber用户数据的访问权限
查看>>
Mysql 数据库操作
查看>>
转:linux终端常用快捷键
查看>>