Web Worker for Android - android

I am new to hybrid application development in Cordova+Sencha.I have developed an app for iOS and it is working fine ,but when moved to Android most of the functionalities are not working because of the use of Web Workers.Is there any alternative for Webworker in Sencha touch or Cordova ,which helps to migrate the existing code without much change and will work on both iOS and Cordova .Please help
Thanks in advance...

You can try 'DroidGap' instead of 'webView' .
For Example:
public class MainActivity extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
super.loadUrl("file:///android_asset/www/index.html");
}
}

Related

Should I Use CordovaWebView or AndroidWebView in my android native App?

I am making a few simple applications for android platform using Phonegap. I used to use the Android WebView to display the html files put in the assets directory like this ....
public class MyQuiz extends DroidGap
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
Soon.. I came to know that this can be done using Cordova Web View too. Is there any difference between the two? Like Performance, Look & feel or anything else? Is my approach Right ?
Here are some useful links which will help you out to understand the exact difference between AndroidWebView and CordovaWebView
https://stackoverflow.com/a/11297966/2266525
http://wiki.apache.org/cordova/CordovaWebView
http://docs.phonegap.com/en/2.2.0/guide_cordova-webview_android.md.html

Android + Phonegap + Admob

As the title suggests I am trying to create an Android app using Phonegap and then trying to insert Admob into it.
I am using this tutorial provided by Adobe and it is working fine. After this when I use this tutorial provided by Google I run into problems.
According to the Google tutorial, I have to change the activity class, below is the original and the second block of code is the altered code. There doesn't seem to be any errors preventing it from compiling. It's just when I try and run it using the Android emulator I get an error stating "Unfortunately MyFirstPhonegapPlugin has stopped"
Note, using the Google tutorial, there are two ways of implementing the code, using just the class below and using a mixture of XML and the class below. I tried the other way and due to getting errors which doesn't let me compile, I've gone for this way.
package com.tricedesigns;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
public class MyFirstPhoneGapPluginActivity 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");
}
}
Adjusted code:
package com.tricedesigns;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
import com.google.ads.*;
public class MyFirstPhoneGapPluginActivity 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");
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
adView.loadAd(new AdRequest());
}
}
I am using Phonegap 1.6.1 and the most up to date SDK for Android and Admob
The way Phonegap is implemented, it pretty much hides all the details about Android and lets you basically implement a mobile web app as a native app. If you care to implement Android natively, I'd recommend reading the Hello World tutorial. The code you have here is crashing on AdView adView = (AdView)this.findViewById(R.id.adView); because you don't have a layout file with an AdView element with id adView.
If you're more interested in the mobile web part of it and plan to continue sticking with Phonegap, your best bet is to try this plugin which lets you make JavaScript calls using the Phonegap framework, and the plugin performs all of the underlying Android calls necessary to get ads.
Here is a fully functional project of what I was looking for
old version phonegap not support extenal jar lib.
but now phonegap add some new feathers.
use phonegap builder ,add config
add some config
<gap:plugin name="com.admob.plugin" version="1.0.0" source="plugins.cordova.io"/>
so not need any java code any more.
just need some js code.
admob.initAdmob("admob banner ID","admob interstitial ID");
admob.showBanner(admob.BannerSize.BANNER,admob.Position.TOP_APP);
this will create and show a admob banner at top of your app.

How to enable cookies for Android phonegap 1.8.0 app?

I understood that in order to use cookies inside of phonegap native app there must be piece of code which enables it.
When building phonegap for iOS using xcode 4 there is such piece of code inside of phonegap template.
Could you please advice me which code and where I need to put in order to enable cookies for Android phonegap 1.8.0 app?
Please note that I'm using the eclipse Indigo 3.7.2 for building of the app.
Many thanks.
Cheers,
Sinisa.
If you are trying to use local cookies (file://) you have to make the parent Phonegap project accept local cookies. To do so, You should have a file called youappname.java in your PhoneGap project, probably with this contents or similar:
import android.os.Bundle;
import org.apache.cordova.*;
public class App 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");
}
}
Modify it to look like this example:
import android.os.Bundle;
import android.webkit.CookieManager;
import org.apache.cordova.*;
public class App extends DroidGap {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
CookieManager.setAcceptFileSchemeCookies(true);
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
you actually wanna do
import android.webkit.CookieManager;
import org.apache.cordova.*;
public class MainActivity extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
try{
CookieManager.setAcceptFileSchemeCookies(true);
}catch(Throwable e){}
Since the CookieManager does not exist on older Android versions
If my memories are good, the Phonegape's template loads your start-up web page (ex: index.html) by loading it from the webview (something like : super.loadUrl("file:///android_asset/www/index.html");). The latter is declared in the main activity (a ".java" file).
So, first, find the instruction that loads your web application. Then, add the following lines before the webview.loadUrl so that you can obtain something like this :
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().startSync();
webView = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
super.loadUrl("file:///android_asset/www/index.html");
Finally, refresh the Android's project and relunch the app.

Issue observed with Android app developed using phonegap

I have developed Android applicationusing Phonegap framework with Eclipse pulgin. am not gettting any error in Eclipse but when i'm running the app am able to see the blank app screen.So can someone help me out this issue..
Sample app developed using this link
Please comment asap..
Code:
Java File ----------
package com.phonegap;
import com.phonegap.*;
import android.os.Bundle;
public class HelloworldActivity extends DroidGap
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_assets/www/helloworld.html");
}
}
The problem is in your loadUrl, you should use:
super.loadUrl("file:///android_asset/index.html"); // Singular android_asset, not assets

how to run local web application in android webview

can anybody tell how to run the local webapplication using android webview
I want to run my own webpages in android using web view
Thanks
I'm guessing you want something like this:
private WebView mWebView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourLayoutWithAWebView);
mWebView = (WebView)findViewById(R.id.yourWebViewIdFromTheLayout);
mWebView.getSettings().setJavaScriptEnabled(true); // Enable JavaScript
mWebView.loadData(yourHtmlData, "text/html", "utf-8");
}
Hopefully, that at least points you in the right direction.
Also, I'd recommend reading the documentation on the WebView, it's pretty thorough.
Just run your application on the emulator, as you normally do (and be sure to have your computer connected to internet).

Categories

Resources