WebView setUserAgentString() fails to load images - java

I set the user agent in webView
mWebview.getSettings().setUserAgentString(getString(R.string.str_user_agent));
String : Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1
When i set the user agent it fails to load some images. If anyone knows the reason or the answer please mention.

Related

Is there any way to exactly implement a "desktop mode" function into my mobile app when loading website content?

Is there any way to exactly implement a "desktop mode" function into my mobile app when loading website content? I'm making a android app, and I want to have a page just with static website content just like in a web browser, I really like how mobile opera implemented this feature, So I just want to know if there is a way to do that. And if there is, then How?
(I'm making this project in Java and viewing the website using WebView from the library "WebKit")
I've also tried changing the User Agent, which didn't work on a static website.
This method helps you to set DesktopMode on webview
public void setDesktopMode(WebView webView,boolean enabled) {
String newUserAgent = webView.getSettings().getUserAgentString();
if (enabled) {
newUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5)\nAppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/85\nVersion/11.1.1 Safari/605.1.15";
}
webView.getSettings().setUserAgentString(newUserAgent);
webView.getSettings().setUseWideViewPort(enabled);
webView.getSettings().setLoadWithOverviewMode(enabled);
webView.reload();
}
Call it like that
Mobile mode : setDesktopMode(webView, false);
Desktop mode : setDesktopMode(webView, true);
For Kotlin:
fun setDesktopMode(webView: WebView, enabled: Boolean) {
var newUserAgent: String? = webView.settings.userAgentString
if (enabled) {
newUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5)\nAppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/85\nVersion/11.1.1 Safari/605.1.15"
}
webView.settings.apply {
userAgentString = newUserAgent
useWideViewPort = enabled
loadWithOverviewMode = enabled
}
webView.reload()
}

HtmlUnit - "Browser Not Supported" Error on website using JQuery

I would like to use HtmlUnit to login to website and click a link so that a file would be downloaded, however, the website, which uses JQuery, returns a "Browser Not Supported" Error. Is there a way that HtmlUnit can be set to look exactly like a normal browser to this website?
Any help would be greatly appreciated.
I'm trying to do this with the following settings, but the error is still occurring:
public void surf(Job job) {
System.out.println("[Enter] surf");
try {
String applicationName = "Netscape";
String applicationVersion = "5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41";
String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41";
int browserVersionNumeric = 51;
BrowserVersion browser = new BrowserVersion(applicationName, applicationVersion, userAgent, browserVersionNumeric);
WebClient webClient = new WebClient(browser);
final HtmlPage page = webClient.getPage("https://www.europasports.com");
System.out.println(page);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("[Exit] surf");
}
Netscape was discontinued in March 2008, that's why you are getting the message. It no longer exists! If you are targeting Apple, i suggest you use Safari, but Google Chrome currently has the largest browser usage share

Youtube API v3 exporting videos

i create a program that take in input some information and search for the first 10 video on youtube, my problem is that the v2 version of Youtube API isn't support, so i change that
https://gdata.youtube.com/feeds/api/videos?q=
with new version,but i dont find that. Can you help me please?
Thanks a lot
EDIT
Thanks a lot , i have tried to do this command
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&q=skyrim&key={YOUR_API_KEY}
i want search the first 10 video related to the keyword Skyrim.
I try this using eclipse and i have this error
Exception in thread "main" org.jsoup.HttpStatusException: HTTP errorfetching URL. Status=400, URL=https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&key={YOUR_API_KEY}&q=skyrim&max-results=10
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:590)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:540)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:227)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:216)
I run the query in this mode :
private static String QueryURL ="https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&key={YOUR_API_KEY}&q=";
Document doc = Jsoup.connect(QueryURL+stringa).userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36").get();
Where stringa is = Skyrim.
Thanks all for help
Start at the YouTube API v3 page: https://developers.google.com/youtube/v3/

Query regarding identifying the different type of devices

I have a query regarding the HTTP request.If i have one server side service which caters requests from different types of devices.How can i know from the HTTP request(user-agent) what type of device (android,IOS) is sending the request.
Thanks in advance.
Learner.
The user agent String will contain Strings such as iPhone, Android, etc...
You can search for such Strings in the user agent using, for example, userAgent.contains("Android").
Here are some sample user agent Strings :
For Android :
Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19
For iPhone :
Mozilla/5.0(iPhone;U;CPUiPhoneOS4_0likeMacOSX;en-us)AppleWebKit/532.9(KHTML,likeGecko)Version/4.0.5Mobile/8A293Safari/6531.22.7
For iPad :
Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25

Tricking Facebook auth into believing that my application is an iPhone

I'm developing an application which will allow users to sign in with their Facebook account. Currently, I'm using Eclipse SWT browser to display the login-browsing window, which works great. However, I'd prefer if this web-browsing window got treated (and therefore styled) as an iPhone. I've tried to force the HTTP-headers to mimic the iPhone's; without any change.
My current code looks somewhat like this:
String[] headers = { "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3" };
browser.setUrl("https://m.facebook.com/dialog/oauth?client_id=appId&redirect_uri=url&state=state", "", headers);
However, the Facebook website STILL realizes that I'm not an iPhone, which makes the output looks like this:
Whilist I'm looking for this design:

Categories