I am working on an Android App with Phonegap Cordova-3.0.0 and when I call InAppBrowser I got MotionEvent mTouchMode = 4 error. And InAppBrowser function is not working. So how can I fix this? Do I need do some setting on AndroidManifest.xml or config.xml?
And I got this on my AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
And I got this on my config.xml
<plugins>
<plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser" />
</plugins>
In Phonegap Cordova-3.0.0 version, for the app to communicate closely with various device-level features, we need to add plugins that provide access to core Cordova APIs.
The cordova plugin add command requires you to specify the repository for the plugin code.
For example, In-app browser:
$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
we need run this in command line. Don't need worries about AndroidManifest.xml or config.xml files. After you run $ cordova build, it will auto write for you.
You could get more idea about it in doc.phonegap
Add following code in config.xml this works fine for mi.
<plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser" />
<access origin="*" browserOnly="true"/>
You have to mention the below code line in config.xml
<plugin name="InAppBrowser" value="CDVInAppBrowser" />
try to add this to your manifest, it helps me with a f*king plugin to work
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
try also not use 'plugin' tag in config.xml, but:
<feature name="InAppBrowser">
<param name="android-package" value="org.apache.cordova.InAppBrowser"/>
</feature>
it will help for future updates of phonegap
To open a link in browser inside the app without opening external browser
HTML
<input type="button" id="button1" value = "click here"
onclick="window.open('https://example.com','_blank','location=yes','closebuttoncaption = Return');">
Now go into your project folder and open Terminal or Command Prompt (Windows) and type the following command:
cordova plugin add cordova-plugin-inappbrowser --save
It will configure the required files and also add the plugin into your config.xml file.
Open your HTML page where you're trying to open the link, and put this JavaScript.
<script src="cordova.js"></script>
<script type = "text/javascript" charset = "utf-8">
function onLoad(){
document.addEventlistner("deviceready", OnDeviceReady, false);
}
function onDeviceReady(){
}
</script>
Related
html5 jquery mobile hybrid phonegap app on android s6 sport using phonegap desktop and phonegap developer app on phone. Not sure of phone gap version (cli not installed properly, tried but opening prompt gives an error) but it is a recent (last week) install.
Using call in chrome opens phone app dialer but not in test phonegap app - click does nothing. Also mailto: and http: acts the same, works in chrome not in app.
The exact html is:
<a id="btn_phone" href="tel:18001231234" rel="external" data-role="button" data-icon="phone"></a>
I added to the config.xml
and based on comments removed the catch-all
which got it working for others but not in my case.
In config file is this:
<access origin="tel:*" launch-external="yes"/>
<access origin="geo:*" launch-external="yes"/>
<access origin="mailto:*" launch-external="yes"/>
<access origin="sms:*" launch-external="yes"/>
<plugin name="cordova-plugin-whitelist" version="1"/>
<allow-intent href="http://*/*"/>
<allow-intent href="https://*/*"/>
<allow-intent href="tel:*"/>
<allow-intent href="sms:*"/>
<allow-intent href="mailto:*"/>
<allow-intent href="geo:*"/>
as stated I removed this:
<access origin="*"/>
So based on everything I've read that should be all I need to do but it is still not working.
Two questions:
Does anyone know a fix for this?
Is there a way to debug this on the phone to see what is failing?
thanks
I struggled with this forever and eventually did the following which worked:
In the HTML:
<input type="button" href="tel:+1-800-555-1234“ class="phone-number" value="1-800-555-1234"/>
In the Javascript:
$(‘.phone-number’).bind(click, function(e) {
e.preventDefault()
var phoneLink = $(e.currentTarget).attr('href');
window.open(phoneLink, '_system', 'location=yes’);
}
What is your cordova version? I think your problem is the white list plugin declaration.
Try this:
<feature name="Whitelist">
<param name="android-package" value="YOUR_WHITELIST_CORDOVA_PATH" />
<param name="onload" value="true" />
</feature>
More info on how to configure White List here: https://www.npmjs.com/package/cordova-plugin-whitelist
NOTE TO ALL This answer does NOT work for CLI. <feature> in this context is meant for SDK and those using an IDE. See Documentation The feature Element
Quote:
If you use the CLI to build applications, you use the plugin command to enable device APIs. This does not modify the top-level config.xml file, so the <feature> element does not apply to your workflow.
If you work directly in an SDK and using the platform-specific config.xml file as source, you use the <feature> tag to enable device-level APIs and external plugins. They often appear with custom values in platform-specific config.xml files.
I upgraded today to the newest Cordova - 5.4.1. App on iOS kept working just fine but not on Android. All requests were returning 404 error, so I dig into the topic and found out that I need "cordova-plugin-whitelist". I installed it and added
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'">
to the header of index.html as well as <access origin="*" /><allow-navigation href="*"/> to config.xml
and now every request to external world is returning "net::ERR_NAME_NOT_RESOLVED"
In AndroidManifest.xml I have those two lines so I guess it's not a problem with Internet access.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
I went through many questions on SO related to cordova-plugin-whitelist but nothing seems to work
My config.xml
```
<?xml version='1.0' encoding='utf-8'?>
<widget id="app" version="1.1.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>app</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<allow-navigation href="*" />
<platform name="ios">...splash screens and icons</platform>
<platform name="android">...splash screens and icons</platform>
<icon src="resources/android/icon/drawable-xhdpi-icon.png" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="3000" />
<preference name="Orientation" value="default" />
<feature name="phonegap-parse-plugin">
<param name="id" value="org.apache.cordova.core.parseplugin" />
<param name="url" value="https://github.com/fastrde/phonegap-parse-plugin" />
</feature>
<feature name="Insomnia (prevent screen sleep)">
<param name="id" value="nl.x-services.plugins.insomnia" />
<param name="url" value="https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git" />
</feature>
<feature name="Toast">
<param name="id" value="cordova-plugin-x-toast" />
<param name="url" value="https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git" />
</feature>
<feature name="Cordova SMS Plugin">
<param name="id" value="com.cordova.plugins.sms" />
<param name="url" value="https://github.com/cordova-sms/cordova-sms-plugin.git" />
</feature>
<feature name="OpenTokCordovaPlugin">
<param name="id" value="com.tokbox.cordova.opentok" />
<param name="url" value="https://github.com/doxyme/cordova-plugin-opentok" />
</feature>
</widget>
```
I have no idea what the issue was but restarting device resolved it. Nothing related to the app, just the phone had difficulties with connecting to Internet even though it was connected to Wi-Fi and signal strength seemed to be on max.
In your app's 'config.xml', place only this:
<allow-navigation href="*" />
And remove what you added to your index.html header.
Then if it still doesn't work that means your problem is not related to the whitelist plugin.
I used this plugin in different Android projects and never had to do more than this to allow my app to communicate with the back-end.
Hope that helps!
We ran into a similar issue where we received the "Failed to load resource net::ERR_NAME_NOT_RESOLVED" error on two different systems from the android emulator running in HAXM using Cordova 6.4.0 and the version 25 (7.1.1) android SDK. Simply removing and adding the whilelist plugin resolved our issue without changing any configuration files.
I was having the same issue and nothing seemed to solve... And I figured out that in my case was the splashscreen image size that was too big (about 3.2MB)... I used this website to compress the file and then worked.
Restarting Device seems to resolve this problem for me locally, but this piece of work always comes back to me from support. So would like to have a fix for the solution not a workaround.
The whitelist plugin also has Content Security Policy declarations:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
This seems to have resolved the issue for me, but only time will tell as I can never get this issue to replicate on demand.
For me, none of the mentioned solutions worked. What worked for me was adding the plugin directly from the repo:
cordova plugin rm cordova-plugin-inappbrowser --force
cordova plugin add https://github.com/apache/cordova-plugin-inappbrowser.git
If the problem persists you can go ahead and remove and add the platform again:
cordova platform save
cordova platform rm <platform>
cordova platform add <platform>
It seems you are trying to send requests yet you are offline, try to check internet connection.
I am trying to access Cordova Contacts API to access the device contact details but i am not able to get the details .I have added the reference of Cordova.js and have added below in Conf.xml ..
<feature name="Contacts">
<param name="android-package" value="org.apache.cordova.contacts.ContactManager" />
</feature>
and i have given permission in AndroidManifest.xml file too..
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
Still on running my application in the OnLoad() event function only i am getting this error because of undefined ..Here is the code..
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
$("#searchby_chooser_ok_button").bind ("click", searchByCriteria);
if (typeof Contact === "undefined") {
getElement("contacts_list").innerHTML = "<p>The Cordova Contacts API is inaccessible</p>";
}
}
I tried my level best to search on web in vain only .Is there any specific file that i need to add into the project?..Please help me to resolve this ..Thanks..Here is my project directory structure
Read the following links for phonegap/cordova project.
http://thejackalofjavascript.com/phonegap-3-cli-setup-mac-windows/
http://coenraets.org/blog/cordova-phonegap-3-tutorial/
http://teusink.blogspot.in/2013/07/guide-phonegap-3-android-windows.html
http://sdk.revmobmobileadnetwork.com/phonegap_cordova.html
http://docs.phonegap.com/en/3.5.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide
Phonegap Cordova installation Windows
I'm writing a Plugman-compatible Cordova plugin. Installing it via Plugman, I've confirmed it installs correctly and runs normally:
plugman --platform android --project /platforms/android --plugin my/plugin.path
But if I use:
cordova build/cordova run android
it doesn't work even with plugin installed. This is because Plugman only installs my plugin js file to the /platforms/android/assets/www folder and not the base /www folder, so when I build, the /www folder without the plugin gets copied to /platforms/android/assets/www.
Is there an option or something in plugin.xml I should be specifying to install the plugin to the project root www folder?
When using Cordova CLI, you shouldn't install plugins using plugman. Cordova CLI does use plugman under the covers, but what you want to use is cordova plugins add http://... or cordova plugins add /path/to/plugin.xml.
You didn't specify which version of Cordova you are using, but here's some examples of adding plugins that are core functionality: http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface
It should put the js files in platforms/android/assets/www/plugins/com.plugin-name/www and the java files in platforms/android/src/com/plugin-name/
You can specify this in the plugin.xml file like this (this is an example from a plugin that I upgraded to https://github.com/aharris88/phonegap-sms-plugin3.0 ()):
<js-module src="www/sms.js" name="Sms">
<clobbers target="window.sms" />
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="Sms">
<param name="android-package" value="com.adamwadeharris.sms.Sms"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.SEND_SMS" />
</config-file>
<source-file src="src/android/Sms.java" target-dir="src/com/adamwadeharris/sms" />
</platform>
I'm writting an android and iphone app using phonegap 3.0.
So far I have been only compiling the apps remotely using phonegap build.
Now I'm trying to add the geolocation plugin to my app, and in iphone was easy, since I only had to modify the config.xml file.
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation" />
</feature>
So far so good, the problem was that when adding geolocation to android, the documentation indicates that I have set the following configuration:
(in app/res/xml/config.xml)
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.GeoBroker" />
</feature>
(in app/AndroidManifest.xml)
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
But I don't have an AndroidManifest.xml file. I could generate the complete android app using:
cordoba platform add android
But I'm not sure if this is what I should do.
Is is what I should be doing? or there is a way to add geolocation without generating the entire android project?
I am a bit confused because you say you are using phonegap 3.0 and you also mention phonegap-build (highest is 2.9). If you are in fact using phonegap-build, the only thing you need is in your config.xml:
<feature name="http://api.phonegap.com/1.0/geolocation"/>
I had the same problem. My geolocation worked on IOS but not on Android. So I Added to config.xml
<feature name="http://api.phonegap.com/1.0/geolocation"/>
As explained by Dom.This was not sufficient. I wanted to share what I did step by step because I lost about 18h of dev time looking for the solution.
This however did not reslove the problem. So I added the plugin using my IDE.
This added the following to the config:
<plugin name="cordova-plugin-geolocation" version="2.2.0" />
I then went inside the plugin.xml under the plugin directorty.
And looked if the following was added.
<!-- android -->
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</config-file>
...
It was, so I rebooted the device. (on the Ionic forum they say, it might help)
When reinstalling the app I checked for the permission. And it was added. So for the bad Q of the last pic but I took a pic with my cam for it. Hope this helps