Reputation: 380
I wonder if it is possible, we get the list of Installed apps by :
PackageManager pm = AppList.this.getPackageManager();
Intent intent = new Intent( Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for ( ResolveInfo rInfo : list)
{
results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm));
}
Can we sort or filter apps that use Internet Access to work?
Upvotes: 0
Views: 593
Reputation: 870
This function will check an activity if it has the internet permission and if that permission is granted. You have to modify it accordingly for a service.
boolean checkIfUsesInet(ResloveInfo rInfo) {
boolean result = false;
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(rInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
for(int i=0; i < packageInfo.requestedPermissions.length; i++) {
String permission = packageInfo.requestedPermission[i];
int permissionFlag = packageInfo.requestedPermissionFlags[i];
if(Manifest.permission.INTERNET.equals(permission) && (permissionFlag & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0)
result = true;
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return result;
}
Upvotes: 0
Reputation: 1006664
You are welcome to retrieve the PackageInfo
corresponding with an application, then examine its requestedPermissions
array to see if the INTERNET
permission is in there.
Upvotes: 1