2015-04-03 20 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用戶許可(的