启动自定义隐式意图(Launching custom implicit intent)

编程入门 行业动态 更新时间:2024-10-21 13:38:07
启动自定义隐式意图(Launching custom implicit intent)

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

First app的活动在其清单中: - where, 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) }

Two activities are installed having the following manifest files on device respectively:

The First app's activity has in its manifest:- where, 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>

The second app's activity has in its manifest:- where, 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>

Now, i want to start one of these activity from third application using the following code:

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

But execution shows an error:-

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) }

最满意答案

您需要提供完整的操作名称 ; 通过在意图中调用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>

Java:

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);

You need to supply the full action name; supply the mimeType you used in manifest by calling setType() in your intent.

Manifest :

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

Java :

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);

更多推荐

android,Intent,活动,电脑培训,计算机培训,IT培训"/> <meta name="description

本文发布于:2023-08-07 09:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463774.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   意图   隐式   Launching   implicit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!