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);
Related
Currently I have written a code to load all capable applications which can view images from the phone.
public static List<String> getAllCapableForFileViewing (Context context, String mimeType) {
List<String> packages = new ArrayList<>();
PackageManager pm = context.getPackageManager();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_VIEW);
sendIntent.setType(mimeType);
List<ResolveInfo> resolveInfoList = context.getPackageManager()
.queryIntentActivities(sendIntent, 0);
for (ResolveInfo resolveInfo : resolveInfoList) {
packages.add(resolveInfo.activityInfo.packageName);
System.out.println(resolveInfo.activityInfo.packageName);
System.out.println(resolveInfo.activityInfo.applicationInfo.className);
System.out.println(resolveInfo.activityInfo.name);
System.out.println("");
}
return packages;
}
When I tried to list all the applications, one of them have two set listed e.g. WeChat, WeChat Moment. Obviously it have two activities which can handle the image for viewing. The problem is the name of the two are the same "WeChat".
Additionally? even though it can consume the content i passed in but they are not really application for viewing images e.g. Gallery application. Is there a way to recognise them. I know it may be impossible.
The problem is the name of the two are the same "WeChat".
Well, in the end, that is up to the developers of that app. However, look at labelRes of the ResolveInfo, as this may be a better label to use (e.g., pulled from the <intent-filter>).
Is there a way to recognise them
You are welcome to try using CATEGORY_APP_GALLERY, though this may lead to false negatives (i.e., apps that the user would expect to show up that do not).
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.
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
}
}