According to my requirement I want to show list of installed apps with last used time.
I am using UsageStatsManager,but it is working only for lollipop. How can I do that?
Try this code
PackageManager pm = context.getPackageManager();
ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0);
String appFile = appInfo.sourceDir;
long installed = new File(appFile).lastModified();
Related
I want to get ApplicationInfo of an app by app uid. Specially I want to get label name of application (the name under application icon).
I know I can list all of installed application and compare this uid with their uid and find label name of application with this uid. But is there a better solution?
Assuming you already have the pid of the application:
PackageManager pm = getApplicationContext().getPackageManager();
String packageName = pm.getNameForUid(pid);
PackageInfo pInfo = pm.getPackageInfo(packageName, 0);
String appLabel = pm.getApplicationLabel(pInfo.applicationInfo);
i am trying to make launcher in android.i want admin to hide few apps from user.
i have done for admin-user log in. now i want admin to select some apps which should not be seen by user.
so that,when user log in he/she should see only those apps which are allowed by admin.
List<ResolveInfo> availableActivities = manager.queryIntentActivities(i, 0);
for(ResolveInfo ri:availableActivities){
AppDetail app = new AppDetail();
app.label = ri.loadLabel(manager);
app.name = ri.activityInfo.packageName;
app.icon = ri.activityInfo.loadIcon(manager);
apps.add(app);
}
i have got the list of apps..
kindly help.
Use PackageManager to get all the installed apps and then write the following code:
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, package_name); //package_name is the name of the application's package you want to hide
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
That should do it.
You can maintain application information i.e name,package name and icon in SQLite databse.
On the basis of selection , you can show applications to user.
I'm wondering if it's possible to check if an application is shipped with Android, for example: Gallery, Contacts, Downloads, Email, etc. all these kind applications are the ones I would like to exclude from a list I'm creating, but don't want to hardcode the names.
This is the code I'm using to grab application names:
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgList = getApplicationContext().getPackageManager().queryIntentActivities(mainIntent, 0);
pkgList contains ResolveInfo objects.
Edit:
One way to check if application is part of Android OS is to check if ResolveInfo.activityInfo.applicationInfo.packageName contains "com.android" char seq., but I'm still interested in a more elegant solution.
See this answer.
Basically, this:
PackageManager pm = getPackageManager();
//Gets the info for all installed applications
List<ApplicationInfo> apps = pm.getInstalledApplications(0);
for(ApplicationInfo app : apps) {
if((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
//It's a pre-installed app
} else if ((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
//It's a pre-installed app with a market update installed
}
}
Does anybody have a simple code to display a list (list view?) of all the apps installed on a phone, and have the user open one when clicked?
Or even an App drawer. I just need a way to have the user open all of their apps.
I have tried searching for tutorials, but couldn't find any, and I downloaded the example home from Android, but I absolutely hate looking through code and digging out what I Want.
Have a look at the Home sample application that comes with the SDK.
The basic idea is to use PackageManager to get either
a list of all installed packages using getInstalledPackages or
a list of all launcher activities using queryIntentActivities for an intent with category CATEGORY_LAUNCHER and action ACTION_MAIN
depending on your use case.
Here you can get all the installed application.Write code to achieve additional requirement
List<ApplicationInfo> packages;
PackageManager pm;
pm = getPackageManager();
get a list of installed apps.
packages = pm.getInstalledApplications(0);
ActivityManager mActivityManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
for (ApplicationInfo packageInfo : packages) {
//packageInfo.packageName is the name of the package
}
Just check this code snippets posted here: http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon , you can have all the installed application.
Rasel's Code worked ok for me.
Here is the full code: (
would love to see some more comments so I understand why it works!)
List<ApplicationInfo> packages;
PackageManager pm = getPackageManager();
packages= pm.getInstalledApplications(0);
Log.v("Alert","package is "+packages);
for (ApplicationInfo packageInfo : packages) {
String tempinfo= packageInfo.packageName;
Log.v("Alert","this is working"+ tempinfo);
I am using the following snippet to get the application name and icon of few of the APKs on my SD Card.
PackageInfo packageInfo = packageManager.getPackageArchiveInfo(apkPath, 0);
ApplicationInfo appInfo = packageInfo.applicationInfo;
Drawable appIcon = appInfo.loadIcon(packageManager);
String appName = appInfo.loadLabel(packageManager).toString();
I am able to access the package name but the loadIcon returns the default Android application icon for all the apks and the loadLabel returns the package name (Not the application label).
I also get the following warning messages in logcat:
Failure retrieving icon 0x7f020005 in package com.sample.radio
Failure retrieving text 0x7f050000 in package com.taskkiller.demo
I am running Android 2.2, any pointers will be appreciated. Thanks.
You may need to add two lines before creating appIcon, AppName:
PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(APKFilePath, 0);
// NEW LINES
pi.applicationInfo.sourceDir = APKFilePath;
pi.applicationInfo.publicSourceDir = APKFilePath;
String AppName = (String)pi.applicationInfo.loadLabel(pm);
Drawable appIcon=pm.getApplicationIcon(pi.applicationInfo);