想了解用于WebView的android中的BasicAuthentication不起作用的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于androidwebview使用的相关问题,此外,我
想了解用于WebView的android中的BasicAuthentication不起作用的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于android webview使用的相关问题,此外,我们还将为您介绍关于Android ShowCaseView的buttonLayoutParams不起作用、Android Webview – navigator.geolocation.getCurrentPosition不能正常工作、android – webView.canGoBack()在使用loadDataWithBaseURL()时不起作用、android – WebView中的视频 – ApplicationContext vs Activity Context的新知识。
本文目录一览:- 用于WebView的android中的BasicAuthentication不起作用(android webview使用)
- Android ShowCaseView的buttonLayoutParams不起作用
- Android Webview – navigator.geolocation.getCurrentPosition不能正常工作
- android – webView.canGoBack()在使用loadDataWithBaseURL()时不起作用
- android – WebView中的视频 – ApplicationContext vs Activity Context
用于WebView的android中的BasicAuthentication不起作用(android webview使用)
嗨,我想从我的android webview 打开此URL http://3864.cloud-
matic.net/,我尝试了很多方法,但该应用程序甚至没有打开mainActivity。我尝试过的如下。
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webView1);
webView.setHttpAuthUsernamePassword("cloud-matic.net/","realm",username,password);
webView.loadUrl("http://3864.cloud-matic.net/");
}
请告诉我我错了。阿里
Android ShowCaseView的buttonLayoutParams不起作用
我使用了这段代码(在库中也一样):
// The following code will reposition the OK button to the left. RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); lps.addRule(RelativeLayout.ALIGN_PARENT_BottOM); lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT); int margin = ((Number) (getResources().getdisplayMetrics().density * 12)) .intValue(); lps.setMargins(margin,margin,margin); View showcasedView = findViewById(R.id.ib_next); ViewTarget target = new ViewTarget(showcasedView); ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions(); co.buttonLayoutParams = lps; co.fadeInDuration = 1000; co.fadeOutDuration = 1000; ShowcaseView sv = ShowcaseView.insertShowcaseView(target,this,R.string.showcase_title,R.string.showcase_details,co);
但它不起作用?任何人都可以告诉问题在哪里?
解决方法
RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); // This aligns button to the bottom left side of screen lps.addRule(RelativeLayout.ALIGN_PARENT_BottOM); lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT); // Set margins to the button,we add 16dp margins here int margin = ((Number) (getResources().getdisplayMetrics().density * 16)).intValue(); lps.setMargins(margin,margin); ViewTarget target = new ViewTarget(R.id.buttonBlocked,this); sv = new ShowcaseView.Builder(this) .withMaterialShowcase() .setTarget(target) .setContentTitle(R.string.showcase_main_title) .setContentText(R.string.showcase_main_message) .build(); // Set declared button position to ShowcaseView sv.setButtonPosition(lps);
这对我有用,希望它对某人有所帮助.
Android Webview – navigator.geolocation.getCurrentPosition不能正常工作
我有一个非常非常简单的场景,我遇到了一个非常常见的问题(随着时间的推移,许多StackOverflow用户都会注意到这一点).但是,我已经尝试了所有提出的解决方案,但它们似乎都不起作用.有人可以一劳永逸地帮助解决这个问题吗?
我正在构建一个Android应用程序(对于Android 7,让我们假设),它包含一个Webview,指向一个实现非常简单的地理定位的网站. (我最新的,非常精简的网站版本只显示用户的纬度和经度.)
我可以在Chrome中查看网站正常(并且它可以完美地显示纬度/体验).但是当我使用Webview运行应用程序时,没有显示任何内容.
在过去的几天里,我已经尝试过看似每个提出的解决方案(在MainActivity.java中),但是没有一个解决方案似乎有效.
我添加了AndroidManifest.xml中可以想到的所有权限.
需要做些什么才能让它发挥作用?
当然,在使用Webview的Android应用程序中查看具有地理位置的网站应该相当简单,对吧???
编辑:我把事情缩小了一点.我在运行时提示用户输入权限,我已经确认允许地理位置.我还确认我的应用程序允许使用Javascript.
关键/核心剩余问题似乎是这样的:
以下内容似乎不适用于Webview.
navigator.geolocation.getCurrentPosition(success, error);
我不知道为什么,但这就是问题所在.
参考:
Android webview error when asking for geolocation
The application does not have sufficient geolocation permissions
Location is accessed in Chrome, doesn’t work in WebView
Android Ask for permission to use location within webview
最小的地理位置网页:
(如何在Android Webview中显示它?)
<!DOCTYPE html>
<html>
<head>
<Meta charset=utf-8 />
<title>Webview Test</title>
</head>
<body>
<div id='output'></div>
<script>
function success(pos) {
var latitude = pos.coords.latitude;
var longitude = pos.coords.longitude;
document.getElementById('output').innerHTML = `Your current position is: Latitude : ${latitude} Longitude: ${longitude}`;
}
function error(err) {
console.warn('ERROR(${err.code}): ${err.message}');
}
navigator.geolocation.getCurrentPosition(success, error);
</script>
</body>
</html>
解决方法:
创建一个JavaScriptReceiver.java类
public class JavaScriptReceiver
{
Context mContext;
/** Instantiate the receiver and set the context*/
JavaScriptReceiver(Context c) {
mContext = c;
}
@JavascriptInterface
public void showShopping(){
Intent intent = new Intent(mContext, ShoppingActivity.class);
mContext.startActivity(intent);
}
@JavascriptInterface
public void showOrders(int orderid){
Intent intent = new Intent(mContext, MyOrdersActivity.class);
intent.putExtra("order",orderid);
mContext.startActivity(intent);
}
}
然后通过WebView的对象调用addjavascriptinterface()接口.
JavaScriptReceiver javaScriptReceiver;
javaScriptReceiver = new JavaScriptReceiver(this);
webView.addJavascriptInterface(javaScriptReceiver, "JSReceiver");
android – webView.canGoBack()在使用loadDataWithBaseURL()时不起作用
一切运行良好,后续对loadDataWithBaseUrl()的调用运行良好,并继续在我的WebView上正确加载,但每当用户按下后退键时,用户只需回到堆栈上的最后一个活动,而不是返回.
我尝试使用以下代码:
// Check if the key event was the Back button and if there''s history if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) { myWebView.goBack(); return true; }
但后来我尝试强制WebView返回,而不检查是否可以,通过:
// Check if the key event was the Back button and if there''s history if ((keyCode == KeyEvent.KEYCODE_BACK)) { myWebView.goBack(); return true; }
但没有任何反应,只是停留在同一个地方.
作为一个FYI,我在调用loadData()时尝试传递null和一个实际的URL,这就是我现在设置它的方法:
view.loadDataWithBaseURL(mUrl,mHtmlData,SearchUtils.MIME_TYPE,SearchUtils.CHARSET,"");
我读了这个answer,但我希望能有更好的运气.
解决方法
第一,
创建一个ArrayList,它将按时间顺序存储您访问的URL.
private ArrayList<String> searchHistory;
从onCreate()初始化它:
searchHistory = new ArrayList<String>();
现在,每次加载网址时,只需将网址字符串添加到历史记录中:
String mUrl = "www.example.com"; searchHistory.add(mUrl); mWebView.loadDataWithBaseURL(mUrl,...);
并且,当用户按下时,通过删除数组的最旧条目来处理它,然后加载删除后剩下的最后一个:
@Override public boolean onKeyDown(int keyCode,KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && searchHistoryPos > 0) { Constants.LogMessage("Handling back keyevent"); //remove eldest entry searchHistory.remove(mUrl); //make the url-to-load be the latest entry after deletion mUrl = searchHistory.get(searchHistory.size); //load the new url mWebView.loadDataWithBaseURL(mUrl...); } }
当然,在调用loadDataWithBaseUrl时,我也传递了预加载的HTML数据.
希望有所帮助!
android – WebView中的视频 – ApplicationContext vs Activity Context
如果要避免内存泄漏,则必须使用ApplicationContext(与Activity上下文相对)来实例化WebView(refer to this)
如果我传入ApplicationContext并且WebView内部的VideoView需要创建一个对话框(通常是“无法播放此视频”),我会收到BadTokenException(refer to this)
我们是否期望在内存泄漏或潜在的ANR之间做出决定?
解决方法
webView = new WebView(getApplicationContext());
今天关于用于WebView的android中的BasicAuthentication不起作用和android webview使用的分享就到这里,希望大家有所收获,若想了解更多关于Android ShowCaseView的buttonLayoutParams不起作用、Android Webview – navigator.geolocation.getCurrentPosition不能正常工作、android – webView.canGoBack()在使用loadDataWithBaseURL()时不起作用、android – WebView中的视频 – ApplicationContext vs Activity Context等相关知识,可以在本站进行查询。
本文标签: