4

安装了两个活动,分别在设备上具有以下清单文件:

第一个应用程序的活动在其清单中具有:- 其中, package="com.example.tictactoe"

<intent-filter>
        <action android:name="com.example.tictactoe.YOYO" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/*" /> 
 </intent-filter>

第二个应用程序的活动在其清单中具有:- 其中,
package="com.example.project"

 <intent-filter>
        <action android:name="com.example.project.YOYO" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/*" /> 
 </intent-filter>

现在,我想使用以下代码从第三个应用程序开始这些活动之一:

i=new Intent();
i.setAction("YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);

但执行显示错误:-

03-11 08:12:30.496: E/AndroidRuntime(1744): FATAL EXCEPTION: main
03-11 08:12:30.496: E/AndroidRuntime(1744): android.content.ActivityNotFoundException:
                    No Activity found to handle Intent { act=ACTION_SEND (has extras) }
4

3 回答 3

6

您需要提供完整的操作名称;通过在您的意图中调用setType()来提供您在清单中使用的mimeType 。

显现 :

<intent-filter>
     <action android:name="com.example.tictactoe.YOYO" />
     <category android:name="android.intent.category.DEFAULT" />
     <data android:mimeType="text/plain" /> 
</intent-filter>

爪哇:

Intent i=new Intent();
i.setAction("com.example.tictactoe.YOYO");
i.setType("text/plain");
i.putExtra("KEY","HI..i am from third app");
startActivity(i);
于 2014-09-09T14:37:24.580 回答
3

您需要提供完整的操作:

i=new Intent();
i.setAction("com.example.tictactoe.YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);

或者(取决于您要启动的项目):

i.setAction("com.example.project.YOYO");

您也可以通过以下方式进行:(直接在构造函数中提供操作)

i=new Intent("com.example.tictactoe.YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);

也松开数据 mimeType 或阅读如何使用它。因为通过 putExtra 是行不通的。

于 2013-03-11T08:36:14.577 回答
0

首先,您需要确保 Intent 的名称是完全限定名称,并且包名称在 Intent 过滤器和触发 Intent 的活动中相同。在这种情况下:“YOYO”应该是“com.example.tictactoe.YOYO”。您还应该删除 mime 类型,因为您没有在 setData() 中包含数据,在这种情况下您使用的是捆绑包。所以你应该有触发意图的活动:

活动射击意图

i=new Intent();
i.setAction("com.example.tictactoe.YOYO");
i.putExtra("KEY","HII..i am from third app");
startActivity(i);

对于清单中的接收活动条目:您需要确保将类别设置为 DEFAULT 并删除数据类型标签。

活动接收意向

<intent-filter>
     <action android:name="com.example.tictactoe.YOYO" />
     <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
于 2015-06-23T10:04:58.240 回答