Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cordova-plugin-tbs-webview
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenProject
cordova-plugin-tbs-webview
Commits
82515606
Commit
82515606
authored
Aug 17, 2019
by
mergen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了js加载mimeType。
parent
1a3a16d5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
+63
-0
platforms/android/src/org/apache/cordova/x5engine/X5WebViewClient.java
+63
-0
No files found.
platforms/android/src/org/apache/cordova/x5engine/X5WebViewClient.java
View file @
82515606
...
@@ -46,6 +46,9 @@ import java.io.FileNotFoundException;
...
@@ -46,6 +46,9 @@ import java.io.FileNotFoundException;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.Hashtable
;
import
java.util.Hashtable
;
import
java.io.IOException
;
import
java.io.InputStream
;
/**
/**
* This class is the WebViewClient that implements callbacks for our web view.
* This class is the WebViewClient that implements callbacks for our web view.
...
@@ -68,6 +71,66 @@ public class X5WebViewClient extends WebViewClient {
...
@@ -68,6 +71,66 @@ public class X5WebViewClient extends WebViewClient {
this
.
parentEngine
=
parentEngine
;
this
.
parentEngine
=
parentEngine
;
}
}
@Override
public
WebResourceResponse
shouldInterceptRequest
(
WebView
webView
,
WebResourceRequest
request
,
Bundle
bundle
)
{
String
url
=
request
.
getUrl
().
toString
();
if
(
url
.
contains
(
".js"
)){
//干掉file:///
String
newUrl
=
url
.
replace
(
"file:///"
,
""
);
Log
.
d
(
"new"
,
newUrl
);
//vendor-es2015.js
String
rootDir
=
"www"
;
String
mimeType
=
""
;
String
encoding
=
"utf-8"
;
//文件名判断bug
if
(
newUrl
.
contains
(
"es2015"
)){
mimeType
=
"application/javascript"
;
}
else
{
mimeType
=
"text/javascript"
;
}
String
fileName
=
rootDir
+
"/"
+
newUrl
;
try
{
InputStream
is
=
this
.
activity
.
getAssets
().
open
(
fileName
);
Log
.
e
(
"file"
,
"------ File loaded ---000-0-------------"
);
return
new
WebResourceResponse
(
mimeType
,
encoding
,
is
);
}
catch
(
IOException
e
)
{
Log
.
e
(
"file"
,
"文件美欲呕找到"
);
e
.
printStackTrace
();
}
}
if
(
url
.
contains
(
".png"
)
||
url
.
contains
(
".svg"
)){
String
newUrl
=
url
.
replace
(
"file:///"
,
""
);
Log
.
d
(
"new"
,
newUrl
);
String
rootDir
=
"www"
;
String
mimeType
=
"image/*"
;
String
encoding
=
"utf-8"
;
String
fileName
=
rootDir
+
"/"
+
newUrl
;
try
{
InputStream
is
=
this
.
activity
.
getAssets
().
open
(
fileName
);
return
new
WebResourceResponse
(
mimeType
,
encoding
,
is
);
}
catch
(
IOException
e
)
{
}
}
return
super
.
shouldInterceptRequest
(
webView
,
request
);
}
/**
/**
* Give the host application a chance to take over the control when a new url
* Give the host application a chance to take over the control when a new url
* is about to be loaded in the current WebView.
* is about to be loaded in the current WebView.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment