2

I want set couple of settings not to be required for my android app so Google' play store will recognize it also useful for tablets. I need add these two lines to my AndroidManifest.xml:

<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />

Since I use PhoneGap build to compile my app, I need somehow add them to the config.xml file, so PhoneGap will add them to the right place during build process (I guess) ... But no success! Is there any specific syntax I need to use to add uses-feature through config.xml file?

Note that I did almost same thing for setting minSdkVersion by adding line below to my config.xml file, and after build I have it in my manifest file:

<preference name="android-minSdkVersion" value="11" />
borna
  • 283
  • 2
  • 16
  • possible duplicate of [Android PhoneGap Config XML user-permission](http://stackoverflow.com/questions/26440655/android-phonegap-config-xml-user-permission) – James Baxter Apr 03 '15 at 14:49
  • 1
    thanks @JamesBaxter for your attention. Point is I checked that even before asking this question, but it didn't help since I want to make them not required instead of making them required for the app... Or maybe I'm missing something about it – borna Apr 03 '15 at 14:53
  • Sorry my fault for not understanding properly - I have make the question a bit clearer in case someone else can help – James Baxter Apr 03 '15 at 14:58
  • My bad for choosing bad title... Thanks for improvement :) – borna Apr 03 '15 at 15:01
  • It'll still be listed for tablets even if you don't put these in, won't it? You need to put a tablet screenshot in the list though. – Subjective Effect Apr 04 '15 at 08:31
  • @SubjectiveEffect... Nope! It's not listed for tablets in the play store and that's the problem! related screenshots are there for 7" and 10" tablets as well! I've read to be able to list it for tablets, need to add these options to manifest as well – borna Apr 04 '15 at 10:53

2 Answers2

2

Found the solution! Based on PhoneGap Documentation - Config File Elements, just need to add something like this to my 'config.xml' file:

<gap:config-file platform="android" parent="/manifest" mode="add">
    <uses-feature android:name="android.hardware.camera" android:required="false" />
    <uses-feature android:name="android.hardware.telephony" android:required="false" />
</gap:config-file>

Adding gap namespace to widget node, is also needed:

xmlns:gap="http://phonegap.com/ns/1.0"
borna
  • 283
  • 2
  • 16
1

<config-file> looks super useful for overriding.... alas it seems that this is a PhoneGap only feature. For Cordova you will probably need to use hooks.

A good example can be found HERE

Ive modified the script to add the features I needed (I need GPS and Camera to be optional features).

module.exports = function (context) {

var fs = context.requireCordovaModule('fs'),
    path = context.requireCordovaModule('path');

var platformRoot = path.join(context.opts.projectRoot, 'platforms/android');


var manifestFile = path.join(platformRoot, 'AndroidManifest.xml');

if (fs.existsSync(manifestFile)) {

    fs.readFile(manifestFile, 'utf8', function (err, data) {
        if (err) {
            throw new Error('Unable to find AndroidManifest.xml: ' + err);
        }

        var insertAt = data.indexOf("</manifest>");

        var optionalFeatures = "<uses-feature android:name=\"android.hardware.LOCATION\" android:required=\"false\"/><uses-feature android:name=\"android.hardware.location.GPS\" android:required=\"false\"/><uses-feature android:name=\"android.hardware.camera\" android:required=\"false\"/><uses-feature android:name=\"android.hardware.camera.autofocus\" android:required=\"false\"/>";

        var result = data.slice(0, insertAt) + optionalFeatures + data.slice(insertAt);

        fs.writeFile(manifestFile, result, 'utf8', function (err) {
            if (err) throw new Error('Unable to write into AndroidManifest.xml: ' + err);
        })

    });
}

};

Then set the hook in config.xml

 <hook type="after_build" src="scripts/afterBuild.js" />

Hope it helps

Community
  • 1
  • 1
HKalsi
  • 333
  • 3
  • 10