How to set cordova webview background, or cache? - android

I'm using cordova webview to wrap my live online webapp.
And I need to set a background for the cordova webview.
Apparently, specifying android:background attribute won't work on cordova webview.
So I'm looking for a way to set a background for cordova webview.
Packaging in either pictures or webpage are OK for me.
Here is a related question I just asked. And as suggested in the answer, I can use the cache to load the webpage in advance. However it is done in runtime. What I need now is to burn the background, or cache into the app.

Try using a Cordova splash screen. The API is here: http://docs.phonegap.com/en/edge/cordova_splashscreen_splashscreen.md.html#Splashscreen
public class splashScreen extends DroidGap
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//super.loadUrl("file:///android_asset/www/index.html");
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("http://www.google.com",10000);
}
}
Make sure that you create a splash.png image and save it in your /res/drawable/ folder.
This should have the effect of displaying a "background" on the WebView while your external URL loads, instead of just showing a black screen.

Related

Android WebView not loading local HTML files

I'm using the standard Android SDK with Ecliple as provided from the Android website.
What I want to to is to have an activity display a WebView that loads a local HTML-file. Everything works fine until I try to load the webview.
I've placed all the index-files I've tried in the project's assets-folder.
This is the code in my activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_assets/www/index.html");
setContentView(webView);
}
When I run the app over ADB, I get the following message in the WebView:
Webpage not available
The webpage at file:///android_assets/www/index.html might be temporarily down or it may have moved permanently to a new web address.
I know this problem has been posted before, and I've tried every single solution out there. But it just won't load. It displays online http-addresses just fine, but it doesn't seem to find any of the local files.
Please help me, this drives me mad.
Change this line:
webView.loadUrl("file:///android_assets/www/index.html");
to this :
webView.loadUrl("file:///android_asset/www/index.html");
is android_asset not android_assets :D. Good Luck

Android Application doesn't read css file completely

hi I have Android App as I embed HTML file , I added my code and when I test the app I noticed that some of css classes doesn't called as #media also the JQuery doesn't called .
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_elaraby_group);
WebView wv=(WebView) findViewById(R.id.web_engine);
wv.loadUrl("file:///android_asset/index.html");
}
Well you have to provide exact same structure you are using in html page in your asses folder.Otherwise it will not get some files referenced in your html file.And hence those CSS and JavaScript code never gets run.So try with providing same structure as your localhost server.

How can I load a webpage inside the phonegap webview?

I want to be able to link to a webpage inside the phonegap webview that loads an external webpage inside the same phonegap webview. If I do this, it loads inside the webview:
public class App extends DroidGap {
#Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("http://google.com");
}
}
However, I want to have an internal page launched first, with a link to the external page, so I do this:
public class App extends DroidGap {
#Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
and I have a link:
Google
but this link launches google outside the app, in the web browser, instead of in the phonegap webview. What can I do to make sure the link to the external page is launched inside the app's phonegap webview?
Ahhh.. Found the answer on this question.
I had to add
<access origin="www.google.com"/>
to the phonegap.xml file.
This seems to have changed, and access origin seems to have no effect. If you're using the cordova whitelist plugin, as seems to be standard. You need to use allow-navigation in your config.xml file. Without this it will open your web browser.
<plugin name="cordova-plugin-whitelist" version="1"/>
<allow-navigation href="https://google.com/*" />
Then you can use window.location = 'https://google.com' to move to another webpage within your JS.
In the latest phonegab (1.7) in Cordova.plist there is a Key: OpenAllWhitelistURLsInWebView set this to YES.

Android, Trying to embed YouTube video in webpage

I’m trying to display a page of embed YouTube videos. I got the code from YouTube website. The page gets displayed correctly when I load it up in the browser but on my embedded web page the YouTube videos do not show the first frame. Its just a black box with the YouTube logo on the bottom. If you click on it, it does play the video. I tread to enable java script, still did not work.
public class cVideos extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videos);
WebView mWeb=(WebView) findViewById(R.id.webvideo);
mWeb.getSettings().setJavaScriptEnabled(true);
mWeb.getSettings().setJavaScriptEnabled(true);
// mWeb.loadUrl("http://www.besttechsolutions.biz/projects/bigbiz/mobvideo.php");
mWeb.loadUrl("http://www.besttechsolutions.biz/projects/bigbiz/videored.php");
}
}
Try embedding &autoplay=1 in the src attribute of the iframe tag in the page source.
Even so, autoplay will not work on Android 2.1 devices, as they cannot support HTML5 video in the browser.

Load Web Page Into my Activity

OK. Have been trying for two weeks to get a simple web page I created in FrontPage (test.htm) to load into my Activity in my Eclipse Emulator. I have placed my page (test.htm) into my 'assets' folder and created the VERY simple code below. I STILL cannot get the page to load into my Emulator. I am using an XML with WebView within a Linear Layout (myxmlfile). Does anybody see anything blatantly wrong?? I have also tried: file:///asset/test.htm but my assets folder is asset(s) with an 's'.
public class Activity5 extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myxmlfile);
WebView x = (WebView) findViewById(R.id.webview);
x.loadUrl("file:///assets/test.htm");
}
}
Please HELP!
Do you have to add this uses permission
<uses-permission android:name="android.permission.INTERNET"/>
into your AndroidManifest.xml ?
I think your html path is not correct. It must be android_asset instead of asset:
x.loadUrl("file:///android_asset/test.htm");

Categories

Resources