Phonegap build: How to explicitly ask for permissions? - android

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>

Related

Develop PhoneGap app for old android device

I have a simple, but useful app for an old android device I want to develop with Cordova PhoneGap. Going through their tutorial, by default, the current version of cordova requires android level 14 api to build apps, but I've done the following to get the app to build on my old 2.3.6 device...
In /config.xml add the following in the platform->android tag
<platform name="android">
<allow-intent href="market:*" />
<preference name="android-minSdkVersion" value="10" />
<preference name="android-targetSdkVersion" value="10" />
</platform
Edit these lines in the /platforms/android/AndroidManifest.xml file
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="fi.blogspot.codinginthecold" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" tools:overrideLibrary="org.apache.cordova" />
Like I said, the HelloWorld app compiles on the device without error, but when I actually run the app, it says the app has unfortunately stopped.
My question: As the above method failed to run the simplest app, what is best way to develop PhoneGap apps for old android devices?
Thanks.

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.

config.xml vs AndroidManifest.xml?

In Cordova/Android, what's the difference between:
/appname/config.xml
/appname/platforms/android/AndroidManifest.xml
Which one do I edit, or do I edit them both?
I'm looking to do things such as:
force portrait mode (I found this setting in config.xml)
specify minimum sdk supported for android. (I found this setting in AndroidManifest.xml)
You support to modify at /appname/config.xml
When you add a platform, ionic will regenerate /appname/platforms/android/AndroidManifest.xml file for you to build android app. So, it will collect the permission from your plugin and config.xml to build AndroidManifest.xml
Only update config.xml (not AndroidManifest.xml as it gets generated whenever you do a build)
For example to do portait add in config.xml:
<preference name="orientation" value="portrait" />
And to set minimum sdk add in config.xml:
<platform name="android">
<preference name="android-minSdkVersion" value="19" />
</platform>

Cannot add cordova-plugin-uid to Visual Studio 2013 project

When trying to add https://github.com/hygieiasoft/cordova-plugin-uid to visual studio via the config.xml designer, it "recognises" there is a plugin, but ends with blank fields for all the properties (version, plugin id, etc.), even if you wait for minutes (most others find all properties in seconds). If you then try and add it, it simply crashes VS and restarts. I have tried with plugins that do not support ALL platforms, with success, but not this one.
Has anyone had any luck adding this to VS or have any ideas. Since the project is cross platform, I would prefer to use the recommended way, even though this is android only, but am open to suggestions. Ultimately, I am only looking for IMEI.
A user suggested using Telerik App Studio, as the process is simpler to copy the plugin into the www folder, but apart from the cost, I would, as noted, prefer keep within the confines of a somewhat recommended way that will continue working when upgrading to VS 2015 and beyond.
Do the following steps -
1) Download the plugin on your windows desktop. Unzip the downloaded file.
2) Add facebookconnect.xml file to the folder where plugin.xml is present. Add your app id and application name. Place the below tags inside resources tag -
<string name="fb_app_id"></string>
<string name="fb_app_name"></string>
3) Modify the plugin.xml file to include facebookconnect.xml file. It should look like below -
<config-file target="res/xml/config.xml" parent="/*">
<feature name="FacebookConnectPlugin">
<param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
</feature>
<access origin="https://m.facebook.com" />
<access origin="https://graph.facebook.com" />
<access origin="https://api.facebook.com" />
<access origin="https://*.fbcdn.net" />
<access origin="https://*.akamaihd.net" />
</config-file>
<source-file src="platforms/android/res/values/facebookconnect.xml" target-dir="res/values" />
<config-file target="AndroidManifest.xml" parent="application">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/fb_app_id"/>
<activity android:label="#string/fb_app_name" android:name="com.facebook.LoginActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar"></activity>
</config-file>
<framework src="platforms/android/FacebookLib" custom="true" />
<!-- cordova plugin src files -->
<source-file src="platforms/android/src/org/apache/cordova/facebook/ConnectPlugin.java" target-dir="src/org/apache/cordova/facebook" />
</platform>
4) Now Go into Visual Studio and add the plugin from the directory where plugin files are present. It will take some time to be added.
Hope this helps you fix the problem.

Phonegap build with android geolocation

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

Categories

Resources