首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从其他应用程序启动我的应用程序?

如何从其他应用程序启动我的应用程序?
EN

Stack Overflow用户
提问于 2010-07-16 04:45:19
回答 2查看 3K关注 0票数 1

如何从其他应用程序启动我的应用程序?(它们不会打包在一起)

--更新

第二个应用的清单:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.helloandroid"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloAndroid"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.HOME"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

        <activity android:name=".HelloAndroid">
            <intent-filter>
                <action android:name="com.example.helloandroid.HelloAndroid" />
            </intent-filter>
        </activity>

    </application>


</manifest>

我用以下方式调用它:

代码语言:javascript
复制
startActivity(new Intent("com.example.helloandroid.HelloAndroid"));

它抛出:

代码语言:javascript
复制
07-16 15:11:01.455: ERROR/Desktop(610): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.helloandroid.HelloAndroid }

Ralated:

How to launch android applications from another application

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-07-16 04:52:44

在第一个应用程序中,您必须修改AndroidManifest.xml。具体地说,您将在要从某处启动的活动的intent-filter中添加一个自定义action

代码语言:javascript
复制
<activity android:name="FirstApp">
  <intent-filter>
    <action android:name="com.example.foo.bar.YOUR_ACTION" />
  </intent-filter>
</activity>

然后,在您的第二个应用程序中,使用该操作来启动活动:

代码语言:javascript
复制
startActivity(new Intent("com.example.foo.bar.YOUR_ACTION"));

关于您的评论的

看起来像是,如果我更改默认名称"android.intent.action.MAIN“,我将无法在虚拟设备

中从

运行该应用程序

记住,你可以想要多少动作就有多少动作。例如:

代码语言:javascript
复制
<activity android:name="FirstApp">
  <intent-filter>
    <action android:name="com.example.foo.bar.YOUR_ACTION" />
    <action android:name="android.intent.action.MAIN" />
  </intent-filter>
</activity>
票数 4
EN

Stack Overflow用户

发布于 2010-07-16 23:28:15

这个问题看起来和我之前回答的today类似。

如果您只想像从启动程序启动时一样启动:

代码语言:javascript
复制
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new ComponentName( "PACKAGE NAME", "CLASS" ));
startActivity(intent);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3259912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档