How to include external android application activity (or external application entirely) as a dependency of a main application?
I understand that intents can be used to employ external activities to accomplish specific tasks, my question is 开发者_Python百科whether those called external activities can be included within the project itself.
For example, if I wanted to include check-in functionality to my application, and knew that google plus has this great check-in activity, would it be possible to include that specific check-in activity for use in my application?
You need the intent of that activity. I think if you have installed G+ app, you need to iterate through the list of Intents you have installed and find the matching one.
List<ResolveInfo> IntentsList= getPackageManager().queryIntentActivities(new Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER), 0);
PackageManager.PERMISSION_GRANTED = 0 in the addCategory
The 1st argument of addCategory()
method varies whether the intent category is CATEGORY_LAUNCHER
, CATEGORY_ALTERNATIVE
or most likely your required intent to be CATEGORY_DEFAULT
. If you know the intent name then you might be able to call it in your activity, also adding it to you manifest as activity in your application.
The short answer is yes, if you had the library project for the external app you want to use. This generally not the best solution because if you could get the source (a big if) and then the user downloaded the app then you'd have to choose which app to complete the intent with (if you didn't use explicit intents) plus you'd have to update your own app when theirs is updated. All this creates overhead on you. An alternative would be to follow the example of the Text-to-Speech library. The Android O/S doesn't come with one preinstalled so whenever the functionality is requested the user is prompted to download the related library. Just uninstall Pico TTS and you'll see what I mean.
精彩评论