Phonegap build with android geolocation - android

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

Related

adding/removing my cordova plugin

I made a cordova plugin for Android applications, but unlike other plugins, this one only uses an Application (App.java) and not a CordovaPlugin class.
When I try to install it for the first time using cordova plugin add, it works fine. When I try to remove it using cordova plugin rm, it doesn't remove the folder from node_modules and keeps the plugin dependency name in the package.json. Besides, it removes some code from the manifest that belongs to another plugin (I've seen this is a consecuence of the edit-file in the plugin.xml, I need to add the Application name to the manifest) and if I try to install it again I will get an error (because it's still holding the node_modules dependency) unless I update the version of the plugin.
Here's my plugin.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="com.test.plugin.applicationTest" version="1.0.0" platform = "Android">
<name>codova-app-plugin</name>
<description>Test</description>
<author>test</author>
<license>Apache 2.0</license>
<keywords>cordova, application</keywords>
<platform name="android">
<config-file parent="/*" target="res/xml/config.xml">
<feature name="applicationTest">
<param name="android-package" value="com.test.plugin.applicationTest" />
</feature>
</config-file>
<source-file src="src/android/App.java" target-dir="src/com/test/plugin/applicationTest" />
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</config-file>
<edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
<application android:name="com.test.plugin.applicationTest.App"/>
</edit-config>
</platform>
</plugin>
Why it isn't removing the node_modules? and what can I do to avoid the deletion of the AndroidManifest tags ?
Edit:
If I remove the edit-config and instead use a hook, I won't delete the AndroidManifest tags, but they won't get executed or throw EACCESS error. Besides, it keeps the node_modules dependencies.
<hook type="after_plugin_install" src="scripts/nameManifest.js" /> -- won't execcute
<hook type="before_plugin_uninstall" src="scripts/uninstallPackage.sh" /> -- EACCESS error
For now, the best I can do is to remove that edit-config and create hooks for the edition of the application name and the execution of npm uninstall

How to specify user-permission in Ionic source code

I need two permissions:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
So far, what I did: I modified platforms\android\AndroidManifest.xml file manually (in Ionic project) and added this two lines, but this file and whole platforms folder are not under source control. As a result, with each clean checkout, these permissions are missing.
Is there a way to specify these two permissions somewhere in Ionic configuration that is in git?
You can use following lines in config.xml
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.CameraLauncher" />
</feature>
Can Refer below link
https://cordova.apache.org/docs/en/3.0.0/cordova/camera/camera.html

How to add third party plugins in my cordova plugin?

I am developing a cordova plugin and I want to publish now. However, I need to invoke some third party plugins in my plugin, such as cordova-plugin-camera and cordova-plugin-googlemaps. Currently I'm merging everything and given source path in plugin.xml manually, which is a poor code management. I want to know if I can add the dependencies in plugin.xml and free my work.
Actually, I'm helping my friends to solve his problem. Read this Doc of plugin.xml. And specifically:
The <dependency> tag allows you to specify other plugins on which
the current plugin depends. The plugins are referenced by their unique
npm ids or by github url.
Therefore, what you should do is simple:
<dependency id="cordova-plugin-camera" version="^1.1.1" />
but be careful when you dealing with feature and permission in manifest.xml, if you still have those issues after addinig those dependencies, you need add them in plugin.xml as well:
<config-file target="res/xml/config.xml" parent="/*">
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.camera.CameraLauncher"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</config-file>
Hopefully it will solve your problem.

Phonegap build: How to explicitly ask for permissions?

I am building a hybrid app for Android and iOS, and using phonegap build cli-5.2.0
I am using a camera plugin
<plugin name="cordova-plugin-camera" source="npm" spec="2.2.0" />
I have this line specified in my config.xml
<preference name="permissions" value="none"/>
<feature name="http://api.phonegap.com/1.0/camera"/>
And I notice that on my android device, it only asks for
read/write access of USB storage. When using the camera to take a photo, android doesn't ask for any permission and the camera just some how works.
I want to know how to explicitly require Camera permission on android prior to app installation? I need to have it because I believe it is causing some other bug related to a video functionality my app has.
I have tried to build without the permission none line, but that did not make any difference.
The way to do it is to add a config-file element. I don't know why it is so hard to find.
<gap:config-file platform="android" parent="/manifest" mode="add">
<uses-permission android:name="android.permission.CAMERA" />
</gap:config-file>

Phonegap - Upgrade to 3.0 problems with API features

Working on Windows with Phonegap 3.0, Android platform, debugging in Eclipse.
I was able to get my old app to compile but I have encountered a new problem when I try to use a feature that is now a plugin.
I have added all the plugins I need through the CLI tool and have added the "feature" data to the config.xml file, so I assume that they are available to be called. The permissions are also set in the manifest file.
FileTransfer
I see that the File Transfer API example code has not changed for 3.0, so I left the call the same in my code. So the file will download but then I get an error that makes my app crash
"
D/CordovaLog(12883): file:///android_asset/www/phonegap.js: Line 932 : Uncaught Error: Error calling method on NPObject!
"
I did some searching for this error and there doesn't seem to be a standard solution?
Perhaps there is a new way to call features that are within plugins? Because I can't play an audio file without getting errors as well. The sound file will play but will cause errors.
"
09-01 20:13:17.274: W/PluginManager(13279): THREAD WARNING: exec() call to Media.startPlayingAudio blocked the main thread for 23ms. Plugin should use CordovaInterface.getThreadPool().
"
I have re-read the media API and there is no mention of a thread pool. I am doing all of my programming in javascript.
Essentially where ever I use a plugin feature the app has major errors. I tried using my record sound feature in my previously working app, and when I call a stop to my recording it throws an error
"
09-01 20:10:04.206: E/AudioPlayer(13279): FAILED renaming /mnt/sdcard/tmprecording.3gp to /sdsub/myapp/Recorded/myRecording.amr
"
I tested the file transfer api again through my file remove function and it also failed
"
09-01 20:16:00.884: W/PluginManager(13279): THREAD WARNING: exec() call to File.remove blocked the main thread for 19ms. Plugin should use CordovaInterface.getThreadPool().
"
it seems like the essential nature of how features work has changed but is not documented anywhere. The API calls seem unchanged from older versions, just how you install the API features is different, but I followed that guide and installed them.
Is there a new API guide that I have missed? because the Phonegap API documentation hasn't changed for how these features are called in 3.0.
Thanks.
my config file
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="NetworkStatus">
<param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager" />
</feature>
<feature name="File">
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>
<feature name="FileTransfer">
<param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>
<feature name="Media">
<param name="android-package" value="org.apache.cordova.media.AudioHandler" />
</feature>
<feature name="Notification">
<param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>
<feature name="SplashScreen">
<param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
</feature>
<feature name="Compass">
<param name="android-package" value="org.apache.cordova.deviceorientation.CompassListener" />
</feature>
my Manifest file
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.INTERNET" />
while you are upgrading your application , the phonegap.jsfile must suppport all the functional script . you can use the suitable version of javascript file like phonegap.0.9.5.js or higher version too . It might be because the phonegap.js didn't contain the necessary function needed by the application . If you see the API they have the phonegap .X.Y.Z.js . so you can try higher one

Categories

Resources