HTML form Input with Phonegap Android development in Eclipse - android

I have a weird problem. I recently developed an App for ios using Phonegap and Xcode. It went well, they are in the App store, everything worked. One of the elements is a simple email form, written in HTML. It looks like this:
<form name="emailformbtn" id="emailformbtn" onsubmit="submitHandler(e);" action="#emailfromBtn">
To: <input type="email" name="emailvarto"/>
Message:<textarea cols="40" rows="8" id="emailmessagebtn" name="emailmessage">Email Message</textarea>
<input type="button" value="send" onsubmit="submitHandler(e);" onclick="emailProcessfromBtn();"/>
</form>
Works in ios using Phonegap and Jquery mobile. So i decided to convert the app into Android. Converting all the ObjectiveC into Java, and the rest should work because they are both Phonegap/Cordova.
I am Using Cordova 2.0 and Android 4.1
A lot of it does, but when I try to touch the input of the emails field, it does nothing, and Eclipse displays the message:
The View is not attached to a window.
Its a Phonegap/Cordova element. I'm not even sure what its trying to say. Is there an issue with Android and Jquery mobile, or does touching input fields in Android using phonegap not invoke native Keyboards?
Any direction or advice on this problem would be greatly appreciated.
Just to make things clearer, even though I followed Phonegap's configuration guide tot he letter, Here is the contents of the Activity.java file:
package uk.co.testdevelopment.testapp.droidapp;
import android.os.Bundle;
import android.view.Menu;
import org.apache.cordova.*;
public class MainActivity extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}

Are you sure your activity is extending 'DroidGap' and not 'Activity'? This definitely sounds wierd and looks more like a problem of the cordova configuration than anything to do with your html

The issue appears to be with the menu that you specified that you're calling inflate on. With ICS and higher, the menu is created when the app is first run and not when the menu is accessed. I would recommend removing your menu code to get rid of the View error.
BTW: Views have to be attached to a root element of an Android View, which is normally handled by DroidGap. DroidGap also has menu handlers as well, and you may want to look at using a Menu Plugin or using the CordovaWebView approach to developing a Hybrid App for Android 4.x.

Related

Enter event doesn't trigger the function on Android device using angular

There are multiple questions with answers related to my problem but unfortunately, none worked for me.
I have to detect the enter pressed on android keyboard and change focus from current matInput to next matInput.
I have tried keyup.enter, keydown and keypress but none worked for me. I implemented directive approach but doesn't trigger method when I am debugging app on Android device. Although, it does trigger the method on browser.
Here is what I am using.
HTML:
<mat-form-field class="ib-input-container-width">
<input matInput data-dependency="lastName" (keypress)="onChange($event.keyCode)" (keyup.enter)="handleNext('lastName')" [formControl]="form.get('FirstName')" type="text" >
</mat-form-field>
<mat-form-field class="ib-input-container-width" >
<input #lastName id="lastName" matInput [formControl]="form.get('LastName')" type="text">
TS:
handleNext(elementId){
let nextElement = document.getElementById(elementId);
console.log(nextElement);
nextElement.focus();
}
onChange(event){
console.log(event.keycode);
}
PS: I am on a working progressive web app using Cordova.
Update
I have tried solution from https://stackoverflow.com/a/28103608/3081929
But ng-change doesn't work either.
the code looks correct,
before running your codova app on android make sure you have compiled the angular project using angular cli and output should be set to www folder

How to load and navigate a website within a Cordova webview

Hello I have built my website, was looking forward to have an app for my responsive website... I went with android webviews but it posed problems with opening filechooser... So I went with Cordova after doing a lot of research. I succeeded in creating a Cordova application an imported it to Android studio. My problem is, when my landing page opens clicking any other link opens the default browser... I don't want this behavior I want all links to open within the app(Using Cordova's webviews)...thanks in advance.
NOTE:Am using Cardova to open a completely remote website no local stuff.
My MainActivity.java look like this
package com.noel.myapp;
import android.os.Bundle;
import org.apache.cordova.*;
public class MainActivity extends CordovaActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
loadUrl("http://www.mywebsite.com");
}
}
The inAppBrowser adds an additional address bar at the top. Instead if you just want in app navigation you can use this solution (borrowed from comment section of this answer)
Add this line in your config.xml file
<allow-navigation href="*://*.example.com/*" />
and inside your index.js add something like this
receivedEvent: function(id) {
// other code
window.location = "https://www.example.com
}
(Although this being an old thread sharing anyways if someone else comes across this)
use cordova-plugin-inappbrowser for that
cordova docs for inappbrowser is here.
after device is ready (deviceready event)
use
var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
after adding the plugin.
basic example is here

Android cordova chromeview : Not implemented reached in virtual quota::SpecialStoragePolicy

I'm working on a phonegap project which contains a canvas overlayed with kinetic.js, which allows a user to pinch zoom and pan around an image, then draw annotations on it. it works spliendidly in a browser and on windows and apple tablets, but of course android is a good bit slower.
as a solution, i've released the app using https://github.com/thedracle/cordova-android-chromeview. after switching my main java class to use ChromeView as the webview, i'm getting this error on startup:
12-03 13:21:09.083: E/chromium(13917): [ERROR:aw_browser_context.cc(191)] Not implemented reached in virtual quota::SpecialStoragePolicy* android_webview::AwBrowserContext::GetSpecialStoragePolicy()
after debugging through the codebase, it looks like the error is triggering here:
private void setNativeContentsClientBridge(int nativeContentsClientBridge) {
mNativeContentsClientBridge = nativeContentsClientBridge;
}
(AwContentsClientBridge.java line 36).
i'm trying to find out what the nativeContentsClientBridge int is. My value is 1611312352 but i haven't a notion of what that represents.
my gut feel is that the chromium browser is missing an implementation for accessing localstorage. i found this bug:
https://github.com/pwnall/chromeview/issues/27
where someone is experiencing the same thing, but there is no solution.
for assistance, this is my main activity class:
package com.companion;
import org.apache.cordova.Config;
import org.apache.cordova.CordovaActivity;
import us.costan.chrome.ChromeSettings;
import us.costan.chrome.ChromeView;
import android.os.Bundle;
public class CompanionApp extends CordovaActivity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
ChromeView chromeView = new ChromeView(CompanionApp.this);
ChromeSettings settings = chromeView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDomStorageEnabled(true);
setContentView(chromeView);
super.loadUrl(Config.getStartUrl());
}
}
Thanks for your help,
Margaret
Don't know if it's normal, but it seems that a method's not implemented in Chromium base code : https://github.com/01org/pa-chromium/blob/master/android_webview/browser/aw_browser_context.cc
Here's that particular method:
quota::SpecialStoragePolicy* AwBrowserContext::GetSpecialStoragePolicy() {
// TODO(boliu): Implement this so we are not relying on default behavior.
NOTIMPLEMENTED();
return NULL;
}
I hope it helps :)

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.

jquery animation not working in android

I have html doc with jquery animation looks very much alike: http://tympanus.net/Tutorials/LittleBoxesMenu/
and it works fine on browser but not working on android WebView .
Why not?
Is there some catch with jquery and android?
EDIT: did some testing on iPhone and everything is working just fine, still no idea why not working in android
Ok, problem solved, quite simple at the end, in android app imported apache.cordova package, extended PhoneGap class and simply loaded URL. And that was it.
package voi.tii.yu;
import org.apache.cordova.*;
import android.os.Bundle;
public class PhonegapActivity extends DroidGap {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/page2/index.html");
}
}
The docs for WebView clearly state that Android's WebView doesn't use JavaScript:
By default, a WebView provides no browser-like widgets, does not
enable JavaScript and web page errors are ignored. If your goal is
only to display some HTML as a part of your UI, this is probably fine;
the user won't need to interact with the web page beyond reading it,
and the web page won't need to interact with the user. If you actually
want a full-blown web browser, then you probably want to invoke the
Browser application with a URL Intent rather than show it with a
WebView.

Categories

Resources