I'm trying to distinguish between system applications and applications installed by user
with the following piece of code:
public void getInstalledApps() {
int flags = PackageManager.GET_META_DATA |
PackageManager.GET_SHARED_LIBRARY_FILES |
PackageManager.GET_UNINSTALLED_PACKAGES;
PackageManager pm = context.getPackageManager();
List<ApplicationInfo> applications = pm.getInstalledApplications(flags);
for(ApplicationInfo appInfo : applications) {
if((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
// System application
Log.i("TESTAPPSYSTEM", pm.getApplicationLabel(appInfo).toString());
} else {
// Installed by user
Log.i("TESTAPPUSER", pm.getApplicationLabel(appInfo).toString());
}
}
}
But in Android Studio's console i saw that:
06-17 15:19:42.639 14822-14822/it.example.myapplication.app I/TESTAPPSYSTEM WhatsApp
On the contrary of others applications installed by user (like Telegram), Whatsapp is seen as a system application, not as one installed by user: why?
Whatsapp is pre-installed either with your Android operating system from the manufacturer or by a ROM you have applied to your phone, you can not change this, however if you have a rooted phone then you can uninstall WhatsApp then install it from the play store so that it is installed as a user application not a system application. Furthermore there are apps out there which close system apps, although once again you would need to have root access to perform this task I believe.
Related
I want to find applications that the user has allowed to install other applications.
I know that if I look for "android.permission.INSTALL_PACKAGES" I would find mainly system packages that can install applications but I'd like to find applications (like the browser, or email) that the user allowed to install applications.
I'm trying the following code to loop through all applications which is obviously wrong as I can not find Chrome, who I allowed to install applications. Any suggestion how to achieve this?
final PackageManager pm = getPackageManager();
for (final PackageInfo pi : pm.getInstalledPackages(GET_PERMISSIONS)) {
try {
Context pcontext = createPackageContext(pi.packageName, 0);
if (ContextCompat.checkSelfPermission(pcontext, Manifest.permission.INSTALL_PACKAGES) == PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Application able to install other apps: " + pi.packageName);
}
}catch (SecurityException|PackageManager.NameNotFoundException ex){
Log.d(TAG, "Exception " + ex);
}
}
If I'm understanding your question correctly, the answer is "that's not allowed."
Third-party apps can't actually install applications (see https://developer.android.com/reference/android/Manifest.permission#INSTALL_PACKAGES). Apps like Chrome call the system installer, they don't get install privileges themselves, so that's why you don't see them on the list.
And there's no way to check which other apps have launched an installer process. That would be a security/privacy issue, as it would mean any app could retrieve a list of other apps a user has installed on their device! Each process is assigned its own linux id and can't directly access data for any other app (i.e. it's sandboxed), using the exact same mechanism, in fact, that prevents one user from querying another user's data on a standard linux system.
Is there away to install secondary app when the user installs the APK?
The secondary app porpoise is to save local data that will be shared between multiple apps and detect + listen to app removal package.
I have seen that Facebook is doing something similar they have 2 apps called (Facebook App installer + Facebook App Manager)
you can do with the help of package name of the other app.
so once your first app is installed in phone , at some point yo can check for other app with the help of package name if it is installed or not by using below code
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
and if that is not the case you can take user to play store to get it installed.
Happy Coding :) !!
I want to install custom apps or apps from google play store in Work Profile without user interaction. It can be done using Android Device Policy app and Android Management API remotely only for play store apps.
I've created custom Work Profile application referring to this sample in android using DevicePolicyManager and DeviceAdminReceiver.
I'm able to enable or disable System apps in my Work Profile using:
packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES;
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, packageFlags);
if (0 == (applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)) {
if (enabled) {
devicePolicyManager.enableSystemApp(componentName, packageName);
} else {
Log.e(TAG, "Cannot disable this app: " + packageName);
return;
}
} else {
devicePolicyManager.setApplicationHidden(componentName, packageName, !enabled);
}
But I can't find any method to install play store apps or any custom apps (.apk files) in my work profile, the way it is done using Android Management API and Android Device Policy app. Is there any way to do it programmatically?
I want to get a list of all apps installed on my device. My code is below:
PackageManager pm = getApplicationContext().getPackageManager();
List<PackageInfo> list = pm.getInstalledPackages(0);
When I try multiple user registered on my device (i.e. Android for Work), the API returns a list from the same user space/managed profile, which makes sense.
My question is, is there an option to get a list of all apps from the device (like Settings - Apps - All apps), no matter where the app is installed?
Use LauncherApps (only can get apps will shown in launcher), you can see how Launcher3 use it
https://developer.android.com/reference/android/content/pm/LauncherApps.html
I want to prevent launching of task manager and Settings applications in my application. For this, I tried to obtain currently running application and checked whether their package name is allowed or not .If it is not allowed then show a new activity.
When work out it is show that the package name of default android Settings application is com.android.settings. Now I have some doubts
Is the Settings application has package name com.android.settings in all android versions? If not, which are they?
How to find package name of Task Manager?
try this
private String querySettingPkgName() {
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfos == null || resolveInfos.size() == 0) {
return "";
}
return resolveInfos.get(0).activityInfo.packageName;
}
For this,I tried to obtain currently running application and checked whether their package name is allowed or not .If it is not allowed then show a new activity.
Fortunately, for the users affected by your app, this will be unreliable.
Is the Settings application has package name com.android.settings in all android versions?
Not necessarily. More importantly, any given firmware can have any number of applications that modify settings, supplied by the firmware author. Some settings can be modified even without being part of the firmware, particularly on rooted devices.
If not,which are they?
You are welcome to make a list of all device manufacturers and ROM mod authors and ask them that question.
How to find package name of Task Manager?
There are any number of "task manager" apps included in devices, ROM mods, and available on the Play Store and other distribution points. You are welcome to make a list of all of them and ask their authors that question.
shell into the device using adb, and invoke:
pm list packages
this will provide you a list of pacakges. from there you will should see:
com.android.settings
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d("Packages", "" + packageInfo.packageName);
}
above code should help you
It's not totally clear what is the scenario.
I guess it is something along the lines of showing off devices to public but not have them f'up the device for others.
Maybe it would be better to do a whitelist instead of a blacklist. Meaning the shop should state which apps should be testable on the devices and then you start your activity if it is any other.
But this again will need maintenance: package names of popular apps may also change. You better provide a way of updating the settings of your app via an online service so you can change the needed packages without physical access to the devices and without having to download and install the complete app.
If you just need a device that goes through many hands and should not be tempered with I suggest using a modified device. I only know of Sonim: they provide a library (needs a Sonim provided hash key in your manifest to use that). With it you can prohibit the altering of many settings without preventing access to the whole settings app.