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.
Related
I want to show some of the applications installed on device in my app. Like Gmail, yahoo, outlook, what's app, etc.
Is it allowed to show installed app icons in my app. e.g.: "Gmail" app installed on a device, then my app will check if "Gmail" app installed? If yes then it will fetch the icon from "Gmail" app using API:
Drawable icon = getPackageManager().getApplicationIcon("com.google.android.gm");
and will display it in my app. So showing icon in my app is allowed?
I think you can use this code.
Drawable icon = getPackageManager()
.getApplicationIcon("com.example.testnotification");
imageView.setImageDrawable(icon);
Yes it's allowed. All custom launchers are doing this. They just fetch info of all installed apps on a device and then just show this in their own way.
For all installed apps you can use this:
// First specify an intent for which you want to find activities
// available on device.
// In most cases you only need the "starter" activity which have
// action "ACTION_MAIN" and category "CATEGORY_LAUNCHER"
Intent i = new Intent(Intent.ACTION_MAIN, null);
i.addCategory(Intent.CATEGORY_LAUNCHER);
// Then you can "ask" a system to give you all activities that can
// be opened with this intent
List<ResolveInfo> allApps = getPackageManager()
.queryIntentActivities(i, 0);
// Iterate over info of all apps and retrieve info you need
for (ResolveInfo ri : allApps) {
// Name of app
CharSequence label = ri.loadLabel(getPackageManager());
// App package name
CharSequence packageName = ri.activityInfo.packageName;
// App icon
Drawable icon = ri.activityInfo.loadIcon(getPackageManager());
}
Source: https://www.androidauthority.com/make-a-custom-android-launcher-837342-837342/
You say:
So showing (their) icon in my app is allowed?
#JonGoodwin: Yes I am looking from copyright issue, is their any?
Intro
A trademark protects your brand image. Namely, your logo or
tagline. You can file for a registered trademark if you want to keep
the integrity of your app without worrying about other developers
taking your brand and creating a similar logo, name, or tagline.
ref2
Case law is complicated.
Hello I use Android. This line you are reading is illegal!.
Android™ should have a trademark symbol the first time it appears in a creative (i.e. the previous line, in this creative answer).
Their icon
Example:
(a) When using their actual logo, the rules are a bit more
complicated.
(b) You cannot use the Facebook “Facebook” logo without their
permission, so this is a no-no:
(c) You can use the Facebook™ “F”. But only in the context that you want to
prompt the reader/viewer to connect to your Facebook page.
When you're trademarking your app, you're protecting yourself from
anyone else from using a similar or confusing name to yours. The
particular design or functionality of an app may be subject to
copyright or patent protection, but a trademark protects the name
of your app, or, the logo associated with your app.
Your icon
Mobile App Icons: They’re Trademarks and You Should Register Them.
The majority of app icons have not yet been registered as
trademarks.
Once a company’s core trademarks are protected, it should consider
filing a trademark application to cover its actual app icon.
I searched all federal case law and all TTAB(Trademark Trial and
Appeal Board) cases and could not find any involving app icon
trademarks.ref3
Disclaimer:
The information provided herein presents general
information and should not be relied upon as legal advice when
anallyzing and resolving a specific legal issue. If you have specific
questions regarding a particular fact situation, please consult with
competent legal counsel about the facts and laws that apply.
Background
Starting from API 25 of Android, apps can offer extra shortcuts in the launcher, by long clicking on them:
The problem
Thing is, all I've found is how your app can offer those shortcuts to the launcher, but I can't find out how the launcher gets the list of them.
Since it's a rather new API, and most users and developers don't even use it, I can't find much information about it, especially because I want to search of the "other side" of the API usage.
What I've tried
I tried reading the docs (here, for example). I don't see it being mentioned. Only the part of other apps is mentioned, but not of the receiver app (the launcher).
The questions
Given a package name of an app, how can I get a list of all of its "app shortcuts" using the new API?
Is it possible to use it in order to request to create a Pinned Shortcut out of one of them?
You need to make yourself the launcher app. After that you can query the packagemanager to get the shortcutinfo for a particular package:
fun getShortcutFromApp(packageName: String): List<Shortcut> {
val shortcutQuery = LauncherApps.ShortcutQuery()
shortcutQuery.setQueryFlags(FLAG_MATCH_DYNAMIC or FLAG_MATCH_MANIFEST or FLAG_MATCH_PINNED)
shortcutQuery.setPackage(packageName)
return try {
launcherApps.getShortcuts(shortcutQuery, Process.myUserHandle())
.map { Shortcut(it.id, it.`package`, it.shortLabel.toString(), it) }
} catch (e: SecurityException) {
Collections.emptyList()
}
}
A full implementation of this can be found here:
https://android.jlelse.eu/nhandling-shortcuts-when-building-an-android-launcher-5908d0bb50d2
Github link to project:
https://github.com/nongdenchet/Shortcuts
LauncherApps is a class provided by the Android framework:
https://developer.android.com/reference/android/content/pm/LauncherApps.html
"Class for retrieving a list of launchable activities for the current user and any associated managed profiles that are visible to the current user, which can be retrieved with getProfiles(). This is mainly for use by launchers. Apps can be queried for each user profile. Since the PackageManager will not deliver package broadcasts for other profiles, you can register for package changes here."
Great Question this was what i was looking for and I get one that might be useful
(Its all about Intent)
https://github.com/googlesamples/android-AppShortcuts
Note: If your app is static its simple to implement.
Updated:::
Here is a link that will show you the difference of dynamic or static shortcuts and its implementation if you like it please up vote.
https://www.novoda.com/blog/exploring-android-nougat-7-1-app-shortcuts/
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.
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").
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