Skip to content

[BugFix] Fix the protocol parses failed in webdemo module #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions webdemo/src/main/assets/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
</head>
<body>
<br>
<a href="yourprotocol://com.spinytech.maindemo/main/sync?1=Hello&2=FromWeb"><p style="font-size:30px;">LOCAL SYNC</p></a>
<a href="your_protocol://com.spinytech.maindemo/main/sync?1=Hello&2=FromWeb"><p style="font-size:30px;">LOCAL SYNC</p></a>
<br>
<a href="yourprotocol://com.spinytech.maindemo:music/music/play"><p style="font-size:30px;">PLAY MUSIC</p></a>
<a href="your_protocol://com.spinytech.maindemo:music/music/play"><p style="font-size:30px;">PLAY MUSIC</p></a>
<br>
<a href="yourprotocol://com.spinytech.maindemo:music/music/stop"><p style="font-size:30px;">STOP MUSIC</p></a>
<a href="your_protocol://com.spinytech.maindemo:music/music/stop"><p style="font-size:30px;">STOP MUSIC</p></a>
<br>
<a href="yourprotocol://com.spinytech.maindemo:pic/pic/pic?isbig=0"><p style="font-size:30px;">OPEN PIC</p></a>
<a href="your_protocol://com.spinytech.maindemo:pic/pic/pic?isbig=0"><p style="font-size:30px;">OPEN PIC</p></a>
<br>
</body>
</html>
7 changes: 4 additions & 3 deletions webdemo/src/main/java/com/spinytech/webdemo/WebActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ protected void onCreate(Bundle savedInstanceState) {


public void dispatchAction(String url) {
if (url.indexOf("your_protocol://") >= 0) {
String command = url.substring("your_protocol://".length());
int index = url.indexOf("your_protocol://");
if (index >= 0) {
String command = url.substring(index + "your_protocol://".length());
try {
LocalRouter.getInstance(MaApplication.getMaApplication()).route(this, new RouterRequest.Builder(this).url(command).build());
} catch (Exception e) {
Expand All @@ -45,7 +46,7 @@ public void dispatchAction(String url) {
class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!TextUtils.isEmpty(url) && url.startsWith("your_protocol://")) {
if (!TextUtils.isEmpty(url) && url.contains("your_protocol://")) {
dispatchAction(url);
} else {
mContentWv.loadUrl(url);
Expand Down