[英]Start new activity on html webview Webpage not available
I find this topic and i did same things on here .I click the button and,it's stay the browser.It's say " Navigation://OpenNativeScreen Webpage not available ".It's should start to activity.But it didn't.So it's not switch to activity. 我找到了这个主题,并且在这里做了同样的事情。我单击按钮,然后一直停留在浏览器中。它说“ Navigation:// OpenNativeScreen网页不可用”。它应该开始活动。但是没有。所以不切换到活动。
public class acilisbir extends AppCompatActivity {
WebView myBrowser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_acilisbir);
myBrowser = (WebView) findViewById(R.id.anasayfagetir);
myBrowser.setWebViewClient(new MyBrowser());
myBrowser.getSettings().setJavaScriptEnabled(true);
myBrowser.loadUrl("file:///android_asset/anasayfa.html");
}
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.equals("Navigation://OpenNativeScreen")) {
startActivity(new Intent(acilisbir.this,AnaEkran.class));
finish();
return true;
}
return false;
}
}
}
And html page.I use button and input for test but i'll use image later instead of this. 和html page。我使用按钮和输入进行测试,但是稍后我将使用图像代替它。
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" charset="utf-8" src="jquery-2.0.0.min.js"></script>
<script type="text/javascript" charset="utf-8" src="quantize.js"></script>
<meta charset="UTF-8">
<title>Full Page Background Image | Progressive</title>
<style>
* { margin: 0; padding: 0; }
html {
background: url(anasayfabuton/bgorg.png) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#page-wrap { width: 400px; margin: 50px auto; padding: 20px; background: white; -moz-box-shadow: 0 0 20px black; -webkit-box-shadow: 0 0 20px black; box-shadow: 0 0 20px black; }
p { font: 15px/2 Georgia, Serif; margin: 0 0 30px 0; text-indent: 40px; }
</style>
</head>
<body>
<style type="text/css" style="display: none !important;">
* {
margin: 0;
padding: 0;
}
body {
overflow-x: hidden;
}
#demo-top-bar {
text-align: left;
background: #222;
position: relative;
zoom: 1;
width: 100% !important;
z-index: 6000;
padding: 20px 0 20px;
}
#demo-bar-inside {
width: 960px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
#demo-bar-buttons {
padding-top: 10px;
float: right;
}
#demo-bar-buttons a {
font-size: 12px;
margin-left: 20px;
color: white;
margin: 2px 0;
text-decoration: none;
font: 14px "Lucida Grande", Sans-Serif !important;
}
#demo-bar-buttons a:hover,
#demo-bar-buttons a:focus {
text-decoration: underline;
}
#demo-bar-badge {
display: inline-block;
width: 302px;
padding: 0 !important;
margin: 0 !important;
background-color: transparent !important;
}
#demo-bar-badge a {
display: block;
width: 100%;
height: 38px;
border-radius: 0;
bottom: auto;
margin: 0;
background: url(/images/examples-logo.png) no-repeat;
background-size: 100%;
overflow: hidden;
text-indent: -9999px;
}
#demo-bar-badge:before, #demo-bar-badge:after {
display: none !important;
}
.image_left1{
margin-top: 50%;
width: 40%;
float: left;
margin-left: 3%;
}
.image_left2{
margin-top: 50%;
width: 40%;
float: right;
margin-right: 3%;
}
.image_left3{
margin-top: 15%;
width: 40%;
float: left;
margin-left: 3%;
}
.image_left4{
margin-top: 15%;
width: 40%;
float: right;
margin-right: 3%;
}
input[type=test] {
background-color: #4CAF50;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
margin-top: 10%;
}
@media only screen
and (min-device-width: 728px)
and (max-device-width: 1024px)
{
.image_left1{
margin-top: 10%;
width: 40%;
float: left;
margin-left: 3%;
}
.image_left2{
margin-top: 10%;
width: 40%;
float: right;
margin-right: 3%;
}
}
</style>
<INPUT TYPE="test" value="Test" onClick="window.location='Navigation://OpenNativeScreen'">
<img class="image_left1" src="anasayfabuton/1tr.png">
<img class="image_left2" src="anasayfabuton/2tr.png">
<img class="image_left3" src="anasayfabuton/3tr.png">
<img class="image_left4" src="anasayfabuton/4tr.png">
</body></html>
UPDATE FOR 2 2更新
I'add my manifest 我加上清单
<activity android:name="Buy" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="activity_buy" />
</intent-filter>
</activity>
Use this code in activity 在活动中使用此代码
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.equalsIgnoreCase("Navigation://OpenNativeScreen")) {
startActivity(new Intent(acilisbir.this,AnaEkran.class));
finish();
return true;
}else if (url.equalsIgnoreCase("activity_buy://Buy")) {
startActivity(new Intent(acilisbir.this,Buy.class));
finish();
return true;
}
return false;
}
}
and html 和html
<INPUT TYPE="buycr" value="Buycr" onClick="window.location='activity_buy://Buy'">
I copied your code into a new project and amended slightly so that it would build. 我将您的代码复制到一个新项目中,并稍作修改以使其得以构建。 I then added a breakpoint to the string compare line and ran in debug mode.
然后,我在字符串比较行中添加了一个断点,并在调试模式下运行。 When the breakpoint is hit I could see that the url actually equaled
"navigation://OpenNativeScreen"
with a lowercase n. 当击中断点时,我可以看到该URL实际上等于
"navigation://OpenNativeScreen"
并带有小写字母n。 See screenshot below: 请参见下面的屏幕截图:
One possible solution would be using the url.equalsIgnoreCase
method so that the case is ignored when compared. 一种可能的解决方案是使用
url.equalsIgnoreCase
方法,以便在比较时忽略大小写。 The full line would be: 全行为:
if (url.equalsIgnoreCase("Navigation://OpenNativeScreen")) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.