Play SWF on android 4.2 webview - android

I am building an App with api level 11. this is my Java Code
myWebView = (WebView) findViewById(R.id.webSitioPublico);
final ProgressBar Pbar;
Pbar = (ProgressBar) findViewById(R.id.progresoSitioPublico);
WebSettings webSettings = myWebView.getSettings();
webSettings.setPluginState(PluginState.ON);
webSettings.setPluginsEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setJavaScriptEnabled(true);
setExplorer(url);
My SWF is on my own external server
with just
<object width="215" height="140">
<param name="movie" value="http://192.168.0.198:5771/es/games/paint.swf">
<embed src="http://192.168.0.198:5771/es/games/paint.swf"
width="215" height="140">
</embed>
</object>
I am testing on a Nexus 7 4.2.2 api level 17, but building this app for api level 11.
Nothing appears on screen just a box with question marks on the place where SWF should be.
my manifest
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="Rafael"
android:hardwareAccelerated = "true">
<activity
android:name="Principal"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:screenOrientation="portrait"
android:hardwareAccelerated = "true"
>
</activity>
<service android:name="ScannerService" ></service>
</application>

But you can still download apk from adobe
http://helpx.adobe.com/fr/flash-player/kb/archived-flash-player-versions.html
it will work in firefox mobile, the default browser (but not chrome mobile)
i have done it and it work on my galaxy nexus with android 4.2.2 :)

I guess it isen't possible anymore.
SWF require Adobe flash who has been deleted from Android
Adobe Removing Flash for Android From Google Play

use it myWebView.load(url) instead of setExplorer(url);

Related

Inline google drive video not playing in webview

My client website http://partidos.online has some embedded videos in his website which are shared from google drive but these videos are not playing in my webview. Hre is the URL for video http://partidos.online/video/47. I want to play this Inline video in this webview.
this is my Manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<application
android:hardwareAccelerated="true"
android:icon="#drawable/logo1"
android:theme="#style/AppTheme">
....
....
</application>
this my MainActivity.java
webView = (WebView) findViewById(R.id.webviewMain);
webView.getSettings().setMediaPlaybackRequiresUserGesture(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setPluginState (PluginState.ON);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache");
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases");
webView.loadUrl(URL);
webView.setWebViewClient(new WebViewClient();
webView.setWebChromeClient(new WebChromeClient(){});
You cannot play videos by WebView from your Google Drive. I suggest creating new YouTube channel and upload that video there. Then set the URL accordingly to URL of your video on YT.

Android WebView don't show html document

I have a html document, I've already tested on the html editor online website (http://htmledit.squarefree.com), it worked fine. However, WebView on android don't show this document, it only show text plain. I have very little experience with html, can anyone help me?
Make sure that your AndroidManifest.xml file includes
<uses-permission android:name="android.permission.INTERNET"/>
just after the
<uses-sdk />
tag. Without this, your app won't be able to access the Internet and therefore webview won't load anything.
HTH
Try -
WebView myWebView = (WebView) findViewById(R.id.webview1);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
This will enable javascript

WebView is not loading HTML5 video in android

WebView wvVideo = (WebView) findViewById(R.id.wvVideo);
String ytVideo= "<html><body><iframe width='350' height='160' src='www.youtube.com/watch?v=yqNGzYsPN6M' frameborder='0' allowfullscreen></iframe></body></html>";
wvVideo.getSettings().setPluginsEnabled(true);
wvVideo.getSettings().setAllowFileAccess(true);
wvVideo.getSettings().setPluginState(PluginState.ON);
wvVideo.getSettings().setBuiltInZoomControls(true);
wvVideo.getSettings().setJavaScriptEnabled(true);
wvVideo.loadData(ytVideo, "text/html", "utf-8");
It just display thumbnail and when i click on that, its not playing. just display black screen. my API Target is 15 and i set all the required permissions for that but still not working.
Your settings seems fine.
As for me the following settings did the job on my project which play HTML5 videos. Try them
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true); // I think you will need this one
webview.getSettings().setPluginState(PluginState.ON);
webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// no need I think
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.setInitialScale(1);
webview.setWebChromeClient(new WebChromeClient()); // dont forget this one
Add android:hardwareAccelerated="true" to your manifest file.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:hardwareAccelerated="true">

JavaScript Alert in Android WebView working only at first time

I am new to Stack Exchange and Andorid development.
I am working on Android webview. I have the following code in my activity class.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView wv;
WebSettings ws;
try {
wv = (WebView) findViewById(R.id.webview);
ws = wv.getSettings();
ws.setJavaScriptCanOpenWindowsAutomatically(true);
ws.setJavaScriptEnabled(true);
wv.clearCache(true);
wv.loadUrl("http://<ip address>:<port>/<context>");
} catch (Exception e) {
e.printStackTrace();
}
}
in layout-main.xml:
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
in AndroidManifest.xml:
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".POCActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
In the url I have index.html with the following code:
<!DOCTYPE html>
<html>
<head>
<title>Contact Example</title>
<script type="text/javascript">
alert("Start");
</script>
</head>
<body>
<p>Database 1</p>
<div id="test"></div>
</body>
</html>
Working Environment:
- Eclipse indigo
- Android SDK min version 10
- Build Target 2.3.3
But the android code is working only once i.e. when I create a new android project and run the same, I can see the javascript alert appearing. From next time the javascript alert is not displayed. Even is any text changes(Say I modified "Database 1" to "Database 2") in the html page is also not displayed.
I tried the following:
- Cleared appcache
- Uninstalled the application and then ran the project again
- Cleared
Please let me know what I am doing wrong here. Any help will be much appreciated.
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
Used these on my code and then my alert() worked pefectly
This is a very old question, but I recently encountered the same problem and would like to share the solution to anyone who come across this later.
You will need to assign a custom WebChromeClient to your WebView to handle the alert.
mWebView.webChromeClient = object : WebChromeClient() {
override fun onJsAlert(view: WebView?, url: String?, message: String?, result: JsResult?): Boolean {
val alertDialog = AlertDialog.Builder(context)
.setMessage(message)
.setPositiveButton("OK") { dialogInterface, _ ->
dialogInterface.dismiss()
result?.confirm()
}
.setOnCancelListener { result?.cancel() }
.setCancelable(true)
.create()
alertDialog.setCanceledOnTouchOutside(true)
alertDialog.show()
//Here AlertDialog is just an example. You can also simply show a Toast.
//But remember to call JsResult.confirm() or JsResult.cancel()
return true
}
}
You need to call either JsResult.confirm() or JsResult.cancel() to notify your WebView whether the user confirmed or canceled the alert dialog. Otherwise, the WebView would assume an alert dialog is still showing(blocking the UI) and won't allow a new one to be shown.

Android webview cannot render youtube video embedded via iframe

This is about loading youtube videos using latest embedded format (iframe) inside a webview.
Example of the iframe embed format
<iframe width="637" height="358" src="http://www.youtube.com/embed/olC42gO-Ln4?fs=1&feature=oembed" frameborder="0" allowfullscreen=""></iframe>
Test the code on Android 2.3.3 & 3.2 devices (HTC Desire & Asus Transformer), the webview would only show a black rectangle.
I tried a similar embed from vimeo
<iframe src="http://player.vimeo.com/video/35693267" width="640" height="360" frameborder="0"></iframe>
In 2.3, video played correctly
In 3.2, a black rectangle flashed and disappeared, the iframe area is blank.
Finally if the old embed format (using the object tag) is used, the video is displayed properly inside the webview in both 2.3.3 & 3.2.
I have checked related questions and added
android:hardwareAccelerated="true"
in the application and/or activity tag but still no video in both 2.3 & 3.2 devices.
This is a big problem because more websites are now using the newest format (iframe) to embed their youtube videos. Android/Youtube Team, please take a look at this problem.
Android browsers are utterly buggy what comes to video playback and embedding. It simply does not work across devices. Trying to get it working is just waste of your time. My suggestion is that you don't try to include <iframe> but simply provide a thumbnail of the video which directly links to YouTube page or h264 file.
Earlier discussion, with a possible solution.
Google Reader-esque optimizing of WebViews on Android
If you want to play videos within your WebView you NEED to load the data with a base URL!
DONT do this:
mContentWebView.loadDataWithBaseURL(null, webViewContentString,
"text/html", "UTF-8", null);
DO THIS INSTEAD:
//veryVeryVery important for playing the videos!
mContentWebView.loadDataWithBaseURL(theBaseUrl, webViewConentString,
"text/html", "UTF-8", null);
The Base URL will be the something like the "original" url of what you are displaying in your WebView. So let's say you are making a news reader, the WebView's base url will be the url of the original story.
Good Luck!
Also remember to set up your WebView...Like so...
mContentWebView.setWebChromeClient(new WebChromeClient());
mContentWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mContentWebView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
mContentWebView.setWebViewClient(new WebViewClient());
mContentWebView.getSettings().setJavaScriptEnabled(true);
You need to have hardware acceleration turned on in the Manifest (only available on SDK 14 and above).
Ex. Hardware Acceleration On:
<application
android:name="com.example.app"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:hardwareAccelerated="true">
<!-- hardwareAccelerated requires SDK 14 -->
...
</application>
HTML5 Video support
In order to support inline HTML5 video in your application, you need to have hardware acceleration turned on, and set a WebChromeClient.
http://developer.android.com/reference/android/webkit/WebView.html
(Hope it help someone)
This worked for me- the code opens youtube site and can play its videos inside WebView:
mWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
String frameVideo = "<html><body>Youtube video .. <br> <iframe width=\"320\" height=\"315\" src=\"https://www.youtube.com/\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
mWebView.loadData(frameVideo, "text/html", "utf-8");
mWebView.loadUrl("http://www.youtube.com/");
mWebView.setWebViewClient(new WebViewClient());
I would suggest using some code to detect the environment of the user... use the iframe code only for ios devices (iphone, ipod, ipad) and use the old code for everyone else.
This Code made exactly fit to different device
webView.setInitialScale(1);
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
Log.e(SimpleBillsConstants.SIMPLE_BILLS, width + "-" + height);
String data_html = "<!DOCTYPE html><html> <head> <meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"target-densitydpi=high-dpi\" /> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> <link rel=\"stylesheet\" media=\"screen and (-webkit-device-pixel-ratio:1.5)\" href=\"hdpi.css\" /></head> <body style=\"background:black;margin:0 0 0 0; padding:0 0 0 0;\"> <iframe style=\"background:black;\" width=' "+width+"' height='"+height+"' src=\""+ VIDEO_URL+"\" frameborder=\"0\"></iframe> </body> </html> ";
webView.loadDataWithBaseURL("http://vimeo.com", data_html, "text/html", "UTF-8", null);

Categories

Resources