调用外部应用 [英] Calling an extrenal application
问题描述
如何从应用程序中调用外部应用程序?
How can I call an external application from my application?
例如:我需要从我的应用程序中调用Shazam
(应用程序).
我可以在logcat
中看到应用程序的程序包名称.
E.g: I need to call Shazam
(application) from my app.
I can see the package name of the application in the logcat
.
这对任何目的都有用吗?
will that be useful for any purpose?
推荐答案
您可以通过以下方式调用第三方应用程序的活动.
You can call a third party application's activity in the following way.
final Intent shazamIntent = new Intent("com.shazam.android");
shazamIntent .setComponent(new ComponentName("com.shazam.android","com.shazam.android.Splash"));
startActivity(shazamIntent );
但是,这不是解决该问题的好方法.如果程序包名称更改(可能性很小)或活动名称更改(Splash
可能更改为其他名称),则应用程序将中断.
如果Shazam具有可以调用以开始收听歌曲的Intent,请使用该Intent(不确定他们是否有Intent).
But, this is not a great way to go about it. In case the package name changes (which is a very remote possibility) or the activity name changes (Splash
could change to something else) your application would break.
If Shazam has an Intent which can be invoked to start listening to a song use that (not sure if they have one).
此外,如果未安装Shazam,请进行必要的检查,以确保您的通话不会崩溃.
Also, do necessary check in case Shazam is not installed so that your call doesn't crash.
这篇关于调用外部应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!