I want to identify list of apps that are installed on phone memory & movable to sdcard.
I am using following function to get list of installed apps.
I have checked Android Source code for InstalledAppDetails but unable to get solution.
Advance thanks
private List<App> loadInstalledApps(boolean includeSysApps)
{
List<App> apps = new ArrayList<App>();
// the package manager contains the information about all installed apps
PackageManager packageManager = getPackageManager();
List<PackageInfo> packs = packageManager.getInstalledPackages(0); //PackageManager.GET_META_DATA
for(int i = 0; i < packs.size(); i++)
{
PackageInfo p = packs.get(i);
ApplicationInfo a = p.applicationInfo;
// skip system apps if they shall not be included
if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1))
{
continue;
}
App app = new App();
app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
app.setPackageName(p.packageName);
app.setVersionName(p.versionName);
app.setVersionCode(p.versionCode);
app.setInstallDir(p.applicationInfo.sourceDir);
app.setInstallSize(calculateSize(app.getInstallDir()));
CharSequence description = p.applicationInfo.loadDescription(packageManager);
app.setDescription(description != null ? description.toString() : "");
if(app.getInstallDir().contains("/mnt"))
{
//app on sdcard
apps.add(app);
}
else
{
//app on phone memory
apps.add(app);
}
}
return apps;
}
The App Install Location is specified on the AndroidManifest.xml of your app. Take a look here for more info. In short:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="preferExternal"
... >
or
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="auto"
... >
Where auto means that the app may be installed on external device but you don't have a preference; and preferExternal means that the app will be installed on external device when possible
Remember that...
If you do not declare this attribute, your application will be
installed on the internal storage only and it cannot be moved to the
external storage.
So, the question is now how to get the androidManifest.xml file from the app. Well, you can take it from the APK (if not deleted after installed). For that issue, take a look at this post: How to parse the AndroidManifest.xml file inside an .apk package
Finally, a great topic about parsing the xml is found on this post, too. Accessing android:installLocation manifest attribute
Cheers,
Aldo
Related
In my widget, when the widget is opened, I want it to open up a new page that shows links to the users already installed applications. The users must be able to add and delete the links as needed and the links would be updated if that application was deleted from the users device. I have already created the ability in my widget to open a new class but I don't know on how to go about linking to user applications. How can I do this?
You have to get the Activity of the app and link it with URI.
For example:
Uri.parse("market://details?id=" + facebookpackagename);
will load the Facebook app from within your app.
Try this code:
PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for(ApplicationInfo packageInfo:packages){
if( pm.getLaunchIntentForPackage(packageInfo.packageName) != null ){
String currAppName = pm.getApplicationLabel(packageInfo).toString();
//This app is a non-system app
}
else{
//System App
}
}
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.
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
}
}
It is possible to parse some information from the apk file using a tool as mentioned here:
How to parse the AndroidManifest.xml file inside an .apk package
My requirement is to parse information like Application name,description, image urls from a link like :
market://details?id=com.replica.replicaisland
Is there any standard way to parse this information without having the apk file ?
is there any RSS feed available based on the identifier "com.replica.replicaisland" ?
There is an open source library android-market-api created by some developers which allow you retrieve some basic app info directly from google's official android market, worth to check it out.
For the first thing you could just download the webpage from the web browser version of the link which would be https://market.android.com/details?id=com.replica.replicaisland
From there you could parse through the source of the page in your own creative way.
As with RSS feed, no clue.
You may want to check out PackageManager and ApplicationInfo to see if it has everything you need.
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
try {
ApplicationInfo appInfo = pm.getApplicationInfo(packageInfo.packageName, 0);
String appFile = appInfo.sourceDir;
long installed = new File(appFile).lastModified();
Log.d(TAG, "lastModified = " + installed);
//Drawable icon = appInfo.loadIcon(pm);
//Bitmap bitmap = ((BitmapDrawable)icon).getBitmap();
}
catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
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);