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
Related
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");
}
}
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.
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.
I am trying to get local cookies (file://) to work on android 3.1+
within ChildBrowser. I found a blog response talking about this
specific issue and how to remedy it with Cookie Manager. I can't
figure out where in the plugin to put the code. Has anyone
successfully implemented this?
Comment Below from http://code.google.com/p/android/issues/detail?id=3739
Comment 16 by edtechk...#gmail.com, Feb 1, 2012
I got this thing working, for Android 2.2, javascript's
document.cookie works fine, just make sure that in your
Webview...javascript is enabled like so:
yourWebViewVariable.getSettings().setJavaScriptEnabled(true);
for Android 3.1 just add this to your java file onLoadInit:
CookieManager.setAcceptFileSchemeCookies(true); //This is the line that specifically makes it work so the other lines is optional
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.acceptCookie();
For those interested, I figured it out. It is not a Childbrowser issue at all. You have to make the parent Phonegap project accept local cookies and then Childbrowser will too.
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");
}
}
package com.phonegap;
import org.apache.cordova.*;
import android.os.Bundle;
public class PhoneGapSampleActivity extends DroidGap {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("assets/www/index.html");
}
}
I use this code for PhoneGap application..
But it shows an error.
I added index.html file in assets/www folder.
But it shows an error ...
Anyone can help me??
Thanks in advance.
You forgot the file:///. Keep in mind it's important to have the three slashes!
Also I think it should be android_asset and not asset.
In my app it is: "file:///android_asset/www/index.html"
Simple Google search came to this :
phonegap doesn't work
The solution was to rename phonegap.0.9.4.js and phonegap.0.9.4.jar to just phonegap.jar and phonegap.js.