本文介绍了在Android上向现有设备管理员添加新的使用策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用以下device-admin.xml的设备管理应用程序
I have a device admin app that uses the following device-admin.xml
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
</uses-policies>
</device-admin>
某些用户已经激活了设备管理员权限.现在,在该应用程序的更新中,我想添加一个新的uses-policy
Some users has already activated the device admin permissions. Now, in an update of the app, I want to add a new uses-policy
<limit-password />
我想知道如何检测是否已通过编程方式添加了新的使用策略,以便我们推动重新激活设备管理员权限?
I am wondering how to detect that new use policies have been added programmatically so that we push the reactivation of the device admin permissions?
推荐答案
AFAIK的唯一方法是从apk中读取device-admin.xml,您可以通过以下方式(从活动中)进行操作:
AFAIK the only way is read your device-admin.xml from your apk, and you can do it in this way (from an Activity):
PackageManager packageManager = getPackageManager();
List <PackageInfo> packageInfoList = packageManager.getInstalledPackages(0);
for (PackageInfo packageInfo : packageInfoList) {
String publicSourceDir = packageInfo.applicationInfo.publicSourceDir;
if (publicSourceDir.contains("your/app/path")) { // or equals, which you prefer
File apkFile = new File(publicSourceDir);
if (apkFile.exists()) {
try {
JarFile jarFile = new JarFile(apkFile);
JarEntry jarEntry = jarFile.getJarEntry("xml/device-admin.xml");
InputStream is = jarFile.getInputStream(jarEntry);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String str;
while ((str = br.readLine()) != null) {
Log.d("entry: ", str); // your entries in the device-admin.xml
}
} catch (IOException e) {
e.printStackTrace();
}
}
break;
}
}
这篇关于在Android上向现有设备管理员添加新的使用策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!