I can create a floating popup window using standout library https://github.com/pingpongboss/StandOut . As I understand this library creates a service which creates a popup window.
Youtube API for Android provides YouTubePlayerView, which can be only used with YoutubeBaseActivity, and which I cannot use because the floating popup window belongs to a service.
Youtube API also provides YoutubePlayerFragment, which also cannot be used because services cannot work with fragments.
There is also WebView, which can be used here, which is not as nice as Youtube API for Android, but better than nothing. It almost works for me. The WebView is displayed inside a floating popup window, and the video is being played, but the video is just black.
Here is WebView code
private static final String FRAME_VIDEO = "<html><body>Video From YouTube<br><iframe width=\"320\" height=\"280\" src=\"https://www.youtube.com/embed/_oEA18Y8gM0\" frameborder=\"0\"></iframe></body></html>";
WebView webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webView.setWebChromeClient(new WebChromeClient());
webView.loadData(FRAME_VIDEO, "text/html", "utf-8");
Maybe one of these options is possible:
Somehow use YoutubePlayerView without YouTubeBaseActivity
Use fragments without activity
Fix the WebView code
Maybe there is some other way to play youtube videos inside a floating popup window
Related
I have a problem with Android Web view.
The slider work fine with Apple but doesn't load on Android WebView.
Can anyone help? www.pgc-usa.net/ivynails
Thanks
I think I know. Web views in Android by default do not have JavaScript enabled. This is because there is someway it can do harm to the app. To enable it though it takes two lines
WebSettings webSettings = yourWebview.getSettings();
yourWebview.setJavaScriptEnabled(true);
You can also set it so that links that are clicked open in the web view. ( Otherwise they open in browser.) to add this you just add
yourWebview.setWebViewClient(new WebViewClient());
All that together will make it come to this:
WebView yourWebview = (WebView) findViewById(R.id.myWebview);
yourWebview.loadUrl("http://www.pgc-usa.net/ivynails");
WebSettings webSettings = yourWebviewgetSettings();
webSettings.setJavaScriptEnabled(true);
yourWebview.setWebViewClient(new WebViewClient());
You can find out more by visiting this page on the Android developer site by clicking this link.
I am trying to make an Android app display a website in a WebView, but only the website home page actually show content properly via the WebView, the other pages completely disregard the website styles and display content with a white background and blue default hyperlinks. I tested the same type of app on iOS and it works fine there. What can I do about it?
This is the method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("http://www.awesomestories.com");
}
Settings should be set. Tricks Like this:
WebSettings settings = webview.getSettings();
settings.setBuiltInZoomControls(true);
settings.setPluginState(PluginState.ON);
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(true);
If you have kept Single Column Setting in WebView remove it, it will work just perfect.
myWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
If you have not kept Single Column setting and still its not working, then check that you have enabled JavaScript or not, if not then enable it.
myWebView.getSettings().setJavaScriptEnabled(true);
Android WebView requires you to explicitly enable javascript.
Styles in the page may be loaded via javascript, and generally websites don't tend to work good without it, so enabling it is important and might solve your problem in addition to that.
myWebView.getSettings().setJavaScriptEnabled(true);
I am developing an android application in which I want to show a website, which have links in it. When any link is clicked, then it plays an online stream.
Till now I have developed an app which work alright. In this I have used webview to display first screen. The live stream is not supported in webview, so I used webchromeclient.
Now the problem is when any link is clicked, a new browser opens and plays the stream and also shows the address bar and address of page loaded page.
I want to hide the address of new loaded page.
and if possible, also I wnt to keep webchromeclient in existing screen, not a new browser.
in this case you have to customize the WebViewClient like this
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// This is my web site, so do not override; let my WebView load the page
return true;
}
}
}
Then create an instance of this new WebViewClient for the WebView:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new MyWebViewClient());
for further have a look on this, and read carefully
How to force WebView to open all the urls inside the application?
You need to override the WebViewClient for your WebView.
See here for the details: it's pretty straight forward.
Notice Step 6 in particular.
To open links clicked by the user, simply provide a WebViewClient for
your WebView, using setWebViewClient(). For example:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
That's it. Now all links the user clicks load in your WebView.
I am trying to use a WebView in my Android application. I am creating my webview in code-side (not in XML). My problem is; when I call loadUrl method of webview, the webview goes fullscreen mode. How can I keep the size of the webview for example 200x200 pixels?
If there is any other option instead of webview, of course welcome :)
Thanks,
Quite possibly what you are seeing is not your activity, but the Browser application, because the URL you linked to did a redirect. Use WebViewClient and shouldOverrideUrlLoading() to catch the redirect and send it back to your own WebView.
#Mahtias Lin, please see my code to create and use WebView;
WebView webView = new WebView(this);
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 416);
WebSettings webSettings = webView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webView.setLayoutParams(p);
webView.loadUrl("http://www.google.com/");
Above code is not set my webview to 416px height.
#CommonsWare, I tried your suggested with following code and amazingly it works, thanks.
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return false;
}
});
But this usage brought some new problems. When I override shouldOverrideURLLoading, the webview displays with no-addressbar, no-navigation (back, forward etc...)?
And also, the webview doenst accept user inputs?
Ok, I am editing my question :)
I searched and I found the following additional set to make webview to able to get inputs;
webView.requestFocus(View.FOCUS_DOWN);
On the other hand, I guess I will create my own back, forward buttons and address-bar for my webview. I will also attach "what happened" to this thread when I create my buttons and address-bar.
Best,
WebView wb=new WebView();
wb.setInitialScale(60);
this is used for set layout of the emulator. 60 means % value. we can use 0% to 100%.
See my reply and comments on
how to show a webview inside an activity in the middle of screen
Apply LayoutParams to your WebView or to the Layout (i.e. LinearLayout) that's surrounding the WebView, if any, i.e. setLayoutParams(LinearLayout.LayoutParams(200, 200));