gpt4 book ai didi

xml - 使用PowerShell脚本从Android list XML文件中删除权限

转载 作者:行者123 更新时间:2023-12-03 01:06:17 24 4
gpt4 key购买 nike

我有一个包含以下内容的 list 文件。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.dlginventory.dev"
android:versionCode="1"
android:versionName="1.0">

<!-- explicity remove -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!-- Approximate location - If you want to use promptLocation for letting OneSignal know the user location. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!-- Precise location If you want to use promptLocation for letting OneSignal know the user location. -->



</manifest>

我想通过Powershell删除最后两个权限,但无法执行此操作。
我能够获得所需的许可,但无法删除。
这是我用来获取内容的脚本。
$androidManifextFile = "C:\Users\BilalAbbasi\Desktop\Temp\AndroidManifest.xml"
$newPackageName = "com.dlginventory"

$xml = [Xml](Get-Content $androidManifextFile) #this loads the config as XML
$rootElements = $xml.get_DocumentElement(); #this gets all root elements only

##$permissionElements = $rootElements.'uses-permission'
##$element1 = $permissionElements.name -eq "android.permission.ACCESS_FINE_LOCATION"
$element1 = $rootElements.'uses-permission'.name -eq "android.permission.ACCESS_FINE_LOCATION"
$element2 = $rootElements.'uses-permission'.name -eq "android.permission.ACCESS_COARSE_LOCATION"

$rootElements.package = $newPackageName #update the package name
$xml.Save($androidManifextFile); #save the file in xml format

我已经测试了“删除子级”并删除了所有功能,但无法这样做。

最佳答案

您可以这样:

$androidManifextFile = "C:\Users\BilalAbbasi\Desktop\Temp\AndroidManifest.xml"
$newPackageName = "com.dlginventory"

$xml = [Xml](Get-Content $androidManifextFile) #this loads the config as XML

# Define a list of nodes to remove
$nodesToRemove = "android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"

# Select all "uses-permission" nodes
# Match them against the list of nodes to remove
# Remove each match from the document
$xml.manifest.SelectNodes("uses-permission") | Where-Object { $_.name -in $nodesToRemove } | ForEach-Object { $xml.Manifest.RemoveChild($_) }

$xml.manifest.package = $newPackageName #update the package name

$xml.Save($androidManifextFile); #save the file in xml format

关于xml - 使用PowerShell脚本从Android list XML文件中删除权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48205075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com