ton*_*nyc 7 android android-intent
我正在开发一个应用程序,我想将Last.fm应用程序集成到其中.基本上,当有人在我的应用程序中查看艺术家时,我想要一个按钮,他们可以点击以打开Last.fm应用程序和艺术家的信息.
这个意图有效,但它会加载一个菜单,询问我想使用哪个应用程序(Browser或Last.fm):
Intent i = new Intent();
i.setData(Uri.parse("http://last.fm/music/" + headliner));
i.setAction("android.intent.action.VIEW");
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
但是,我只是想启动Last.fm应用程序并跳过询问使用哪个应用程序的对话框,我想可能使用setPackage()方法会像这样工作:
i.setPackage("fm.last.android");
Run Code Online (Sandbox Code Playgroud)
但它导致应用程序崩溃:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://last.fm/music/Rihanna pkg=fm.last.android }
Run Code Online (Sandbox Code Playgroud)
是否可以启动Last.fm应用程序?这是Last.fm的AndroidManifest.xml的副本供参考.
谢谢你的阅读,托尼
Mat*_*adt 14
是的,这是可能的,但您需要知道正确的组件名称.定期启动last.fm应用程序并检查日志文件以查找启动应用程序时使用的cmp = ...信息.然后在您的应用中使用此功能.
我从我的应用程序中启动市场上的Z-DeviceTest应用程序,没有这样的问题:
final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");
intentDeviceTest.setComponent(new ComponentName("zausan.zdevicetest","zausan.zdevicetest.zdevicetest"));
startActivity(intentDeviceTest);
Run Code Online (Sandbox Code Playgroud)
在我的情况下,我从logcat获取的信息是:
// dat = content://applications/applications/zausan.zdevicetest/zausan.zdevicetest.zdevicetest
// cmp = zausan.zdevicetest/.zdevicetest
为了知道如何使用正确的组件/类启动应用程序...对last.fm应用程序执行相同操作
编辑: 我已经测试从我自己的应用程序启动Last.fm,这没有任何错误工作正常:
final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");
intentDeviceTest.setComponent(new ComponentName("fm.last.android","fm.last.android.LastFm"));
startActivity(intentDeviceTest);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11130 次 |
| 最近记录: |