Well i'm working for a simple webview to display a website of course..this website has a mobile version but when i try to run the application the webview displays the desktop mode. I tryied every way but nothing seems to work.. I tryied to change the user agent but nothing..
This is the part of user agent i'm using now
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U;`
Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like
Gecko) Version/4.0 Mobile Safari/530.17");
Of course doesn't work.
Another one (doesn't work)
webview.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 4.2.2; Nexus 7Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19");
And many others but none works. What can i do?
EDIT with my code
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // Request progress circle
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
WebSettings websettings = webview.getSettings();
websettings.setJavaScriptEnabled(true);
webview.getSettings().setUserAgentString("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");
setProgressBarIndeterminateVisibility(true); // Show progress circle
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
setProgressBarIndeterminateVisibility(false); // Hide progress circle when page loaded
activity.setTitle("Title");
}
});
if (savedInstanceState == null)
{
webview.loadUrl("http://forum.ubuntu-it.org/");
}
}
Use the Following Snippet hope this will work with you
webview.getSettings().setUserAgentString("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");
[...] when i try to run the application the webview displays the desktop
mode.. [...] I tryied to change the user agent but nothing..
Try to remove "webview.getSettings().setUserAgentString(.. "..
Android open in "mobile mode" by default..
[...] when i try navigate and click in some link it ask if i want open
it with a browser.
To open links clicked by the user inside your WebView, simply provide a WebViewClient for your WebView, using setWebViewClient(). For example:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
http://developer.android.com/guide/webapps/webview.html
Related
I'm making an Android App with Java in Android Studio for my website using webview, but i've a lot of links which go out of website. How can i detect if link redirect from www.mywebsite.com to www.anotherwebsite.com and open it in another page intent?
You can use the code below.
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new MyWebViewClient());
and create and inner class
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
}
You can find complete documentation here
I want to play a video in the WebView but somehow I get an blackscreen on the video but I can hear the sound of it. Would be really glad if someone can help me
public class MainActivity extends AppCompatActivity {
WebView displayYoutubeVideo;
TextView button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String frameVideo = "<html><body>Video From YouTube<br><iframe
width=\"560\" height=\"315\"
src=\"https://www.youtube.com/embed/WtO3_tF8niU\" frameborder=\"0\"
allowfullscreen></iframe></body></html>";
WebView displayYoutubeVideo = (WebView) findViewById(R.id.youtube_view);
displayYoutubeVideo.getSettings().setUserAgentString("Mozilla/5.0
(Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0");
displayYoutubeVideo.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
WebSettings webSettings = displayYoutubeVideo.getSettings();
webSettings.setJavaScriptEnabled(true);
displayYoutubeVideo.loadData(frameVideo, "text/html", "utf-8");
}
}
I guess you might be missing android:hardwareAccelerated="true" in the permissions of your activity in the manifest file. Since you are playing a flash video this should work out to make the WebView flash enabled. This is something that I encountered and the resolution was to add this permission.
This link may help you.It seems you missed some properties for the web view.
https://inducesmile.com/android/embed-and-play-youtube-video-in-android-webview/
You must activate Hardware acceleration if your android:targetSdkVersion is lower than 11 and have to set webChromeclient to your webview
displayYoutubeVideo.setWebChromeClient(new WebChromeClient());
and in your manifest file add below line
<application android:hardwareAccelerated="true" ...>
I am trying to play an youtube video inside an android app by using the url of the video.I have tried using the following code:
new Thread(new Runnable() {
#Override
public void run() {
myWebView = (WebView) findViewById(R.id.webView1);
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebChromeClient(new WebChromeClient());
try {
myWebView.loadUrl(icobj.video_URL);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
It works, but the problem is that there is a black screen shown for about 4 seconds before the page opens.How do i get rid of the black screen before the page opens?
Check this link. You can listen the webview and show a placeholder or progress bar until loaded. It is all up to you.
It's two days i can't start my webview directly in mobile mode. When i open the application for the first time starts the webview displays the desktop. My code
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // Request progress circle
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
WebSettings websettings = webview.getSettings();
websettings.setJavaScriptEnabled(true);
webview.getSettings().setUserAgentString("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");
setProgressBarIndeterminateVisibility(true); // Show progress circle
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
setProgressBarIndeterminateVisibility(false); // Hide progress circle when page loaded
activity.setTitle("Title");
}
});
if (savedInstanceState == null)
{
webview.loadUrl("http://forum.ubuntu-it.org/");
}
}
Even if i changed the User Agent doesn't work! I tryied every way. I hope in a help from someone, Thanks.
Add this line before loadUrl()
webview.setWebViewClient(new WebViewClient());
When I make a call to my WebView and give it a URL I want it to open within the app (i.e. on my page) but it doesn't always do this.
Some pages will open within my app but others will open in the default android web browser.
Here's my code. Any help on this would be much appreciated.
WebView webView = ((WebView)findViewById(R.id.website));
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webView.loadUrl(website);
To override the default behavior, use something like:
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
More or less duplicate of the existing question Clicking URLs opens default browser?