我制作的应用需要知道设备中的哪个应用有权访问互联网。 有人可以帮帮我吗? (我搜索了我的问题,但我一无所获。)
答案 0 :(得分:2)
你可以这样检查
PackageManager p = getPackageManager();
final List<PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS);
for (int i=0; i < appinstall.size(); i++)
{
PackageInfo packageInfo = appinstall.get(i);
PermissionInfo[] permissions = packageInfo.permissions;
// permissions The array of all the permissions
}
希望这能解决你的问题...
答案 1 :(得分:1)
我找到了最好的解决方案(对于Kushal答案而言) 这是一个功能,提供有权访问互联网的应用列表
private List<PackageInfo> getAppsWithInternetPermission(){
List<PackageInfo> appsThatHaveInternetPermissin = new ArrayList<PackageInfo>();
PackageManager p = getPackageManager();
final List<PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS);
for (int i=0; i < appinstall.size(); i++)
{
PackageInfo packageInfo = appinstall.get(i);
permissions = packageInfo.requestedPermissions;
try{
for (String permissinName : permissions) {
if(permissinName.equals("android.permission.INTERNET")){
appsThatHaveInternetPermissin.add(packageInfo);
}
}
} catch(NullPointerException e){
Log.i("catch messege", e + "");
}
}
return appsThatHaveInternetPermissin;
}