2014-01-06 152 views
0

我试图从我的应用程序启动另一个应用程序,特别是splashtop远程流式传输应用程序。这是我到目前为止有:启动外部应用程序

string packageName = "com.splashtop.remote.FirstActivity"; 
Intent splash = new Intent(); 
splash.SetAction(packageName); 
StartActivity(splash); 

在我的Android清单:

<activity android:name="com.splashtop.remote.FirstActivity" android:label="@string/app_name"> 
    <intent-filter> 
     <action android:name="com.splashtop.remote.FirstActivity" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
</activity> 

而且我得到了应用程序的输出此错误和应用程序forcecloses:

Didn't find class "com.splashtop.remote.FirstActivity" on path: /data/app/roughapp.roughapp-1.apk 

那么如何我是不是改变了它所指的路径

on path: /data/app/roughapp.roughapp-1.apk 
+0

你为什么要在Android Manifest中声明活动?这是告诉Android系统“我写了这个代码,它会在我的包” – panini

+0

与voyboy的好图片 – Ogen

+0

哈哈感谢之人 – user3163793

回答

0

更好的解决方案是使用PackageManager及其方法getLaunchIntentForPackage(String packageName);

http://developer.android.com/reference/android/content/pm/PackageManager.html#getLaunchIntentForPackage%28java.lang.String%29

此方法将返回一个可用的意图,或者如果应用程序未安装或没有这种意图,则返回null。

PackageManager可以通过getPackageManager();

好运从任何语境检索。

+0

那么我该如何使用它?在编码方面我仍然很新,而Android则更是如此。谢谢! – user3163793

+0

startActivity(getPackageManager()。getLaunchIntentForPackage(“com.splashtop.remote”)); //假设它是正确的包 –

+0

出现错误:名称'getPackageManager'在当前上下文中不存在。对不起,如果我错过了一些明显的东西 – user3163793

0

如果您在您自己的清单中声明该Activity,它会在您自己的应用程序中查找它。要推出自己的应用程序之外的活动,删除你把你的清单什么,使用下面的代码:

Intent intent = new Intent(); 
intent.setComponent(new ComponentName("com.splashtop.remote","FirstActivity")); 
startActivity(intent); 
+0

好吧,对不起,我搞砸了清单的事情,我很新。 我没有你所说的做什么,它给了这个错误: “Android.Content.Intent”不包含“ACTION_MAIN”,没有扩展方法“ACTION_MAIN”接受类型的Android的“第一个参数的定义。 Content.Intent“可以找到(你是否缺少使用指令或汇编参考?) – user3163793

+0

我的不好,你不应该包括这一点。看看我更新的答案。 –

+0

所以我认为这是我得到的想法,我应该在我的清单文件中声明它。当我现在运行它时,它给了我这个:[mono-rt] android.content.ActivityNotFoundException:无法找到显式活动类{com.splashtop.remote/com.remote.FirstActivity};你有没有在你的AndroidManifest.xml中声明这个活动? – user3163793

相关问题