How to differentiate the applications with same name in android? - android

In android I am listing the installed application list and storing in my private db. In that some application have same name, example there are 4 application named Maps, If one application gets update, other 3 applications records in private db get updated. How to differentiate those applications? I have used following code to get the installed application list.
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> list = pm.queryIntentActivities(intent,
PackageManager.PERMISSION_GRANTED);
ArrayList<String> applist = new ArrayList<String>();
ArrayList<String> packlist = new ArrayList<String>();
for (ResolveInfo rInfo : list) {
packlist.add(rInfo.activityInfo.packageName);
applist.add(rInfo.activityInfo.applicationInfo.loadLabel(pm)
.toString());
}

Use install paths as unique identifiers (they won't be installed in the same dir).
On the other hand, read this article if you have time. Packages have their configuration which contains UID. The link is from this answer.

You shouldn't differentiate two applications by their names. Some applications don't even have names associated with them (i.e. they are empty). The only sure way to distinguish two applications is by their package name (and this is heavily used by OS too).
Also note that while package name will always be the same, the UID of the application might change if application is fully uninstalled and then reinstalled again.

I'd like to add one little clarification that wasn't mentioned here.
Although there can't be two apps with the same package name, there can be several launcher activities within one app that user can see in launcher app. Yes, as you noticed, standard "Maps" application ("com.google.android.apps.maps" package) has several launcher activities like "Local", "Navigation", "Maps". It doesn't matter for user if these "apps" (or activities, in developer terms) are implemented in one application package or not.
Activity name ("com.google.android.maps.MapsActivity", you can retrieve this string by rInfo.activityInfo.name) is not unique itself too, because anyone can create an app with unique package name and an activity located in java package com.google.android.maps called MapsActivity.
Thus, if you want to find unique identifier for all these launcher activities, you should use combination of both app package name ("com.google.android.apps.maps") and activity name ("com.google.android.maps.MapsActivity").

Related

How to get a list of all the installed apps on an android device and store the names of the apps in a string array?

I have done some research on how to get the information of all the installed apps from the following link.
How to get a list of all installed apps on a android device
The code that the link gave was the following code:
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
I did some research but could not find the answer to my following two questions.
Is there a way to get the NAME of the apps instead of the package name?
Can I store that in a string array (String[] nameofappsinstalled)?
My goal is to just make a simple app that has all the name of the apps installed and put them in a listview. The listview takes in a String[] (string array) and the apps are returned in a List class.
I have done some research on how to get the information of all the installed apps from the following link. How to get a list of all installed apps on a android device
That does not give the list of the installed apps. It gives a list of the launchable activities. An app can have zero, one, or several launchable activities, though most usually only have one.
Is there a way to get the NAME of the apps instead of the package name?
The List you get back is really a List<ResolveInfo>. Call loadLabel() on each ResolveInfo, passing your PackageManager as a parameter, to get the label for the activity.
Can I store that in a string array(String[] nameofappsinstalled)?
Sure, though an ArrayList<String> would be easier and more flexible.

Android Market list apps by package name

Its possible list apps by the package name it uses?
Example:
com.google.earth
com.google.android.apps.giant
And get a list with only two apps?
EDIT:
I want open google play store app in my device and search apps by multiples packages name.
Imagine this picture but with other apps... exactly the app with package name "com.google.earth" and "com.google.android.apps.giant"
From the official documentation, there is no way to achieve this.
You can only open a single app detail page:
market://details?id=<package_name>
the list of app from a developer:
market://search?q=pub:<publisher_name>
Or a search query
market://search?q=<seach_query>&c=apps
Yes, it is possible to do so. You can use the PackageManager as follows, which will grab all of the installed apps and put them in a List. Then, you can grab the two apps that you want from that List and store them in another list.
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
You can iterate over the List as follows:
for (ApplicationInfo packageInfo : packages) { ... }
In that loop, you can:
Get the installed package name:
packageInfo.packageName
Get the source directory:
packageInfo.sourceDir
Launch the Activity:
pm.getLaunchIntentForPackage(packageInfo.packageName)

How to find the package name of default settings application

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.

How to Tell if a Service Can be Used in My App

I hope the terminology is correct as I am relatively new to Android App development, but...
How can I tell the following:
1) If another App provides a 'service' that my App can use?
2) How to access it?
Here is an example of what I'm talking about.
Suppose I know of an App that provides the locations of restaurants (I think there are a few) and I create an App that Rates Italian Restaurants. A user puts in the name of an Italian Restaurant (into my App) and my App spits out a Review and ALSO uses information provided by the 'Restaurant Locator App' to display to the user WHERE this restaurant is.
My question is: How do I know if the 'Restaurant Locator App' provides this information for my App to use and - IF SO - how do I access it?
Not looking for code examples here - just general explanations.
Thanks!
Somewhat tangential, but I've used the following to see if there's anything that will respond to an intent action:
public static boolean doesIntentHaveServices(final Context context,
final String action) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
final List<ResolveInfo> list = packageManager.queryIntentServices(intent, 0);
return list.size() > 0;
}
you can change queryIntentServices to queryBroadcastReceivers and more. See the PackageManager documentation.
The technology exists, and it's called Content Providers. See docs for class ContentResolver for client access, ContentProvider for implementing a service.
Whether existing restaurant locator apps actually have a content provider that your app can call is another big question. Rather unlikely, IMHO. And even if they do, the schema would be, most likely, different between apps.
To list providers that a particular application has, use the PackageInfo class.

Android - check for presence of another app

I'm working on an app that extends the functionality of another, existing app. I want to know what the easiest way is to determine, through code, whether the first app is installed, preferably by referencing it by com.whoever.whatever but almost any criteria would be helpful.
android.content.pm.PackageManager mPm = getPackageManager(); // 1
PackageInfo info = mPm.getPackageInfo(pName, 0); // 2,3
Boolean installed = info != null;
Used in an activity, you need a context to get the PackageManager
Throws PackageManager.NameNotFoundException, I guess. check!
pName is something like 'com.yourcompany.appname', the same as the value of 'package' in the manifest of the app
The recommended way is to check whether the other application publishes an Intent. Most Intent are not owned by a particular app, so, say, if you're looking for a program that publishes "sending mail" intent, the program that gets opened may be Gmail application or Yahoo Mail application, depending on the user's choice and what was installed in the system.
You may want to look at this: http://developer.android.com/guide/topics/intents/intents-filters.html
Starting Android 12, this requires android.permission.QUERY_ALL_PACKAGES permission, which Google Play may or may not allow you to have
See more details https://developer.android.com/training/package-visibility

Categories

Resources