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);
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 get the package name of the default android clock (stock clock).
This is the intent I use to open the stock clock.
Intent i = new Intent(AlarmClock.ACTION_SHOW_ALARMS);
I have tried
i.getPackage();
But this returns null. Is there a way to get the package name of the default clock in android, in any phone?
But this returns null
That is because you have not set the package name in the Intent.
Is there a way to get the package name of the default clock in android, in any phone?
Not really, as there is no concept of a "default clock" in Android.
However, you can use PackageManager and queryIntentActivities() to see what activities will respond to the Intent that you have constructed.
Hope this will help you:
final PackageManager packageManager = this.getPackageManager();
Intent intent = new Intent(AlarmClock.ACTION_SHOW_ALARMS);
List<ResolveInfo> packages = packageManager.queryIntentActivities(intent,0);
for(ResolveInfo res : packages){
String package_name = res.activityInfo.packageName;
Log.w("Package Name: ",package_name);
}
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();
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 trying to develop an android app that could list all app's which has cache, I successfully got the information about cache, but now I want to display those app which has some cache in the screen, I have the package name, but problem is how to get the application name from package name,
Let's say package name is com.android.browser
then app name will be Browser
How to achieve this task ?
Please don't mind if this question is silly to you, please help me in solving this riddle,
Thanks in advance.
You need to use PackageManager to get detailed information about installed packages.
PackageManager packageManager = context.getPackageManager();
ApplicationInfo applicationInfo = null;
try {
applicationInfo = packageManager.getApplicationInfo(packageName, 0);
} catch (final NameNotFoundException e) {}
final String title = (String)((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???");
Try to use PackageManager#getActivityInfo();
There is field which contain app name.