安卓:启动一个活动为不同的第三方应用程序 [英] Android: Starting An Activity For A Different Third Party App

查看:128
本文介绍了安卓:启动一个活动为不同的第三方应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个应用程序,我想了Last.fm应用程序集成到它。基本上,当有人在看我的应用程序一个艺术家,我想有一个按钮,就可以挖掘开拓Last.fm应用程序与艺术家的信息。

I'm working on an app and I want to integrate the Last.fm app into it. Basically, when someone is looking at an artist in my app, I would like to have a button that they can tap to open up Last.fm application with the artist's information.

这个意图的作品,但它加载一个菜单,问其应用程序,我想用(浏览器或Last.fm):

This intent works, but it loads a menu asking which app I would like to use (Browser or Last.fm):

Intent i = new Intent();
i.setData(Uri.parse("http://last.fm/music/" + headliner));
i.setAction("android.intent.action.VIEW");
startActivity(i);

不过,我只是想启动Last.fm应用程序,并跳过对话框,询问要使用的应用程序,我想用的setPackage()方法可能会工作是这样的:

However, I just want to start the Last.fm app and skip the dialog asking which app to use, I thought maybe using the setPackage() method would work like this:

i.setPackage("fm.last.android");

但它会导致应用程序死机:

But it causes the app to crash:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://last.fm/music/Rihanna pkg=fm.last.android }

是否有可能只是开始Last.fm应用程序? 这里的 Last.fm的Andr​​oidManifest.xml中的一份,仅供参考。

Is it possible to just start the Last.fm app? Here's a copy of Last.fm's AndroidManifest.xml for reference.

感谢您的阅读, 托尼

推荐答案

是的,这是可能的,但你需要知道正确的组件名称。定期推出的last.fm应用程序,并检查日志文件中的CMP = ......,当应用程序启动一个已经使用的信息。在你的应用程序,然后利用这一点。

Yes, it's possible but you need to know the correct component name. Launch the last.fm app regularly and check the logfile for the cmp=... information that's been used when the app is started. Use this as well in your app then.

我开始从内我的应用程序市场的Z-DeviceTest应用程序没有这样的问题:

I start the Z-DeviceTest app from the market from within my app without a problem like this:

final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");                
intentDeviceTest.setComponent(new  ComponentName("zausan.zdevicetest","zausan.zdevicetest.zdevicetest"));
startActivity(intentDeviceTest);

在我来说,我从logcat中采取了信息是:

in my case the info I took from the logcat was:

// DAT =内容://applications/applications/zausan.zdevicetest/zausan.zdevicetest.zdevicetest

// dat=content://applications/applications/zausan.zdevicetest/zausan.zdevicetest.zdevicetest

// CMP = zausan.zdevicetest / .zdevicetest

// cmp=zausan.zdevicetest/.zdevicetest

为了知道如何下手正确的组件/类的应用程序...做同样的last.fm应用程序

in order to know how to start the app with the right component/class... do the same for the last.fm app

编辑: 我测试过,从我自己的应用程序推出Last.fm,这工作得很好,没有任何错误:

final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");                
intentDeviceTest.setComponent(new ComponentName("fm.last.android","fm.last.android.LastFm"));
startActivity(intentDeviceTest);

这篇关于安卓:启动一个活动为不同的第三方应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆