我已经完成了一个简单的Android应用程序与本地菜单和web视图与我的网站内容。 我需要检测我的网站是否包含在webview中以隐藏菜单栏。
经过长时间的研究,我发现了这种方式:
if($_SERVER['HTTP_X_REQUESTED_WITH'] == "myAppPackage"){
//the site is included in webview
}
此解决方案适用于很多设备,但对于Galaxy S4 Mini(Android 4.2.2),此变量为空白!
其他htp头部变量:
PATH / usr / local / bin:/ usr / bin:/ bin UNIQUE_ID U6LV8AAAEAABFtKXcAAADY HTTP_HOST主机名 HTTP_ACCEPT text / html,application / xhtml + xml,application / xml; q = 0.9,/; q = 0.8 HTTP_USER_AGENT Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 27.0.1453.116 Safari / 537.36 HTTP_REFERER http://webx225.aruba.it/CP/index.php HTTP_ACCEPT_ENCODING gzip,deflate,sdch HTTP_ACCEPT_LANGUAGE it-IT,它; q = 0.8,en-US; q = 0.6,en; q = 0.4 HTTP_COOKIE PHPSESSID = 5deb3527097d0f767aba45d0aa042; acopendivids =纳达; acgroupswithpersist =纳达; wooTracker = lzp5HpPQNDCd; __utma = 250126209.968543423.1402584011.1403102882.1403106109.27; __utmc = 250126209; __utmz = 250126209.1402752662.8.2.utmcsr =谷歌| utmccn =(有机)| utmcmd =有机| utmctr =(未%20provided) HTTP_CACHE_CONTROL max-stale = 0 HTTP_CONNECTION保持活动 HTTP_X_BLUECOAT_VIA b1ae316f3a2874e7 SERVER_SIGNATURE没有值 SERVER_SOFTWARE Apache / 2.2 SERVER_NAME主机名 SERVER_ADDR 62.149.140.235 SERVER_PORT 80 REMOTE_ADDR 62.249.32.77 DOCUMENT_ROOT / web / htdocs / hostname / home / SERVER_ADMIN postmaster @ hostname SCRIPT_FILENAME / web / htdocs / hostname / home / aruba__php__test .php REMOTE_PORT 43924 GATEWAY_INTERFACE CGI / 1.1 SERVER_PROTOCOL HTTP / 1.1 REQUEST_METHOD GET QUERY_STRING没有任何价值 REQUEST_URI / aruba__php__test .php SCRIPT_NAME / aruba__php__test .php PHPRC没有价值
感谢greenapps的想法,这是最终的解决方案。
Android APP MainActivity :
public View onCreateView
....
WebView webView = (WebView) rootView.findViewById(R.id.my_webview);
String agentModified = webView.getSettings().getUserAgentString().concat(" MobileApplication(mypackage)");
webView.getSettings().setUserAgentString(agentModified);
网址 :
if(strpos($_SERVER['HTTP_USER_AGENT'], 'com.vivicrema.android') !== false)
$isMobileApp = true;
它像一个魅力!
链接地址:
http://www.djcxy.com/p/48803.html
上一篇:
Android WebView detection in PHP
下一篇:
What is the best way to get the URL of a 404'd file after redirect?