2015-04-03 54 views
1

我想设置几个设置不需要我的Android应用程序,所以谷歌的Play商店将认识到它也适用于平板电脑。 我需要这两行添加到我的AndroidManifest.xml:PhoneGap - 使Android功能可选

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

由于我使用的PhoneGap构建编译我的应用程序,我需要以某种方式将它们添加到config.xml中文件,这样的PhoneGap将它们添加到构建过程中的正确位置(我猜)...但没有成功!是否有任何特定的语法我需要使用添加uses-featureconfig.xml文件?

注意,我几乎做了同样的事情,通过添加下面我的config.xml文件线路设置的minSdkVersion,构筑后,我有它在我的清单文件:

<preference name="android-minSdkVersion" value="11" /> 
+0

可能重复http://stackoverflow.com/questions/26440655/ android-phonegap-config-xml-user-permission) – 2015-04-03 14:49:19

+0

感谢@JamesBaxter的关注。我在问这个问题之前检查了点,但它没有帮助,因为我想让它们不是必需的,而不是让它们成为应用程序所需的东西......或者我错过了一些关于它的信息 – borna 2015-04-03 14:53:23

+0

对不起,我的错不能正确理解 - 我已经提出了一个更清晰的问题,以防其他人可以帮助 – 2015-04-03 14:58:16

回答

2

找到了解决办法!基于PhoneGap Documentation - Config File Elements,只需要像这样添加到我的“的config.xml”文件:

<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> 

添加差距命名空间构件节点,还需要:

xmlns:gap="http://phonegap.com/ns/1.0" 
1

<config-file>看起来超有用的重写....唉似乎这是一个PhoneGap唯一的功能。对于科尔多瓦,你可能需要使用挂钩。

一个很好的例子可以发现HERE

伊夫修改脚本中加入我需要的功能(我需要GPS和摄像头是可选功能)。

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); 
     }) 

    }); 
} 

};

然后设置钩config.xml中

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

希望它能帮助[Android的PhoneGap的配置XML用户许可(的