I make an app that need to know which application in device have permission to access to internet .
Anyone can help me?
( I searched my question but I found nothing.)
you can check it this way
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
}
Hope this will solve your problem...
I found the best solution (thanx for Kushal answer)
This is a function that give list of apps that have permission of access to internet
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;
}
Related
I want to check any app version in phone ( android studio )
and if the last version equal the version install in users phones app
How to get any app version installed on the phone by Android Studio?
You need to iterate all application installed the app, then get each of the package name to get the package info.. in packageInfo have infomation about those app
final PackageManager packageManager = getPackageManager();
List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
List<String> vers = new ArrayList<>();
for (ApplicationInfo appInfo : installedApplications)
{
PackageInfo packageInfo = getPackageManager().getPackageInfo(appInfo.packageName, 0);
vers.add(packageInfo.versionName);
}
Log.i(TAG,vers.toString());
Get all install app info:
List<PackageInfo> packList = getPackageManager().getInstalledPackages(0);
for (int i=0; i < packList.size(); i++)
{
PackageInfo packInfo = packList.get(i);
if ( (packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)
{
String appName = packInfo.applicationInfo.loadLabel(getPackageManager()).toString();
;
Log.e("App " + Integer.toString(i), appName +" ver: "+packInfo.versionCode);
}
}
More info:Info
As a safety measure I would like to get the list of apps that aren't installed from the Play Store. Is there a way to do this?
The packageManager contains a method getInstalledApplications but I don't know which flags to add to get the list. Any help would be appreciated.
Edit: Here is an code example of v4_adi's answer.
public static List<String> getAppsFromUnknownSources(Context context)
{
List<String> apps = new ArrayList<>();
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> packList = packageManager.getInstalledPackages(0);
for (int i = 0; i < packList.size(); i++)
{
PackageInfo packInfo = packList.get(i);
if (packageManager.getInstallerPackageName(packInfo.packageName) == null)
{
apps.add(packInfo.packageName);
}
}
return apps;
}
This is a good start, however this also returns a lot off pre-installed Android and Samsung apps. Is there anyway to remove them from the list? I only want user installed apps from unknown sources.
The following link has answer to your question
The PackageManager class supplies the getInstallerPackageName method that will tell you the package name of whatever installed the package you specify. Side-loaded apps will not contain a value.
How to know an application is installed from google play or side-load?
Originally I thought it would be enough to retrieve the apps that weren't installed via the Google Play Store. Later I found that I also needed to filter out the pre-installed system applications.
I found the last part of the puzzle in another post: Get list of Non System Applications
public static List<String> getAppsFromUnknownSources(Context context)
{
List<String> apps = new ArrayList<>();
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> packList = packageManager.getInstalledPackages(0);
for (int i = 0; i < packList.size(); i++)
{
PackageInfo packInfo = packList.get(i);
boolean hasEmptyInstallerPackageName = packageManager
.getInstallerPackageName(packageInfo.packageName) == null;
boolean isUserInstalledApp = (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0;
if (hasEmptyInstallerPackageName && isUserInstalledApp)
{
apps.add(packInfo.packageName);
}
}
return apps;
}
I am new to android programming.
I want to list all the process which uses/access certain resources like :
File(s)
Internet etc
Any sample code or suggestion.
Thanks in Advance ...:)
You will get all application name which is using internet,
private ArrayList<String> getInstalledAppsWithSpecificPermission(Context context) {
ArrayList<String> appsPkgName = new ArrayList<String>();
PackageManager pm = context.getPackageManager();
List<PackageInfo> appNamelist = pm.getInstalledPackages(0);
Iterator<PackageInfo> it = appNamelist.iterator();
while (it.hasNext()) {
PackageInfo pk = (PackageInfo) it.next();
if ((pk.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
Log.d("System Application which using internet = ", ""+pk.applicationInfo.loadLabel(pm));
continue;
}
if (PackageManager.PERMISSION_GRANTED == pm
.checkPermission(Manifest.permission.INTERNET,
pk.packageName))
results.add("" + pk.applicationInfo.loadLabel(pm));
}
Log.v("Application using internet = ", appsPkgName.toString());
return results;
}
I have to detect programatically weither google apps and google services are installed on a device or not.
A first solution is to use the packagemanager :
private static final String GooglePlayStorePackageNameOld = "com.google.market";
private static final String GooglePlayStorePackageNameNew = "com.google.vending";
void someMethod() {
packageManager = getApplication().getPackageManager();
List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo packageInfo : packages) {
if (packageInfo.packageName.equals(GooglePlayStorePackageNameOld) ||
packageInfo.packageName.equals(GooglePlayStorePackageNameNew)) {
googlePlayStoreInstalled = true;
break;
}
}
}
But is there something more reliable ?
I find an other way in testing the result of a market intent
PackageManager pm = getPackageManager();
Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=dummy"));
List<ResolveInfo> list = pm.queryIntentActivities(market, 0);
if (list != null && list.size() > 0)
mMarketInstalled = true;
else
mMarketInstalled = false;
What do you think about this solution ?
How to get exactly "Unknown Sources" application list on Android?
what is flag to used? If it is not this method,what are others method? and
How to programmically?
PackageManager pm = this.getPackageManager();
final List<PackageInfo> appinstalled = pm
.getInstalledPackages(what is flag??); //
Sorry for my bad English.
Thank you.
Someone else may have a better solution, but here's the best I could come up with...
Iterate through all installed packages, comparing each one against a known "good" package that has a good signature, with checkSignatures(int, int) or checkSignatures(String, String). If the return value of checkSignatures is SIGNATURE_UNKNOWN_PACKAGE, then you've got a package from an unknown source.
Otherwise, it doesn't look like any of the flags to getInstalledPackages are intended to filter for unknown sources.
I know this is an old post but I think the following answer might help you:
https://stackoverflow.com/a/42248268/2212770
public static List<String> getAppsFromUnknownSources(Context context)
{
List<String> apps = new ArrayList<>();
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> packList = packageManager.getInstalledPackages(0);
for (int i = 0; i < packList.size(); i++)
{
PackageInfo packInfo = packList.get(i);
boolean hasEmptyInstallerPackageName = packageManager.
getInstallerPackageName(packageInfo.packageName) == null;
boolean isUserInstalledApp = (packageInfo.applicationInfo.flags &
ApplicationInfo.FLAG_SYSTEM) == 0;
if (hasEmptyInstallerPackageName && isUserInstalledApp)
{
apps.add(packInfo.packageName);
}
}
return apps;
}