开发者

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 displa开发者_JAVA百科y 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜