Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在应用程序之间使用隐式意图的自定义操作_Android_Android Intent_Android Manifest - Fatal编程技术网

Android 在应用程序之间使用隐式意图的自定义操作

Android 在应用程序之间使用隐式意图的自定义操作,android,android-intent,android-manifest,Android,Android Intent,Android Manifest,我一直在尝试让两个独立应用程序中的两个活动使用自定义操作和隐式意图进行通信 第一个应用程序(服务器)具有以下清单: <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name="edu.example.sharing.manager.SecureF

我一直在尝试让两个独立应用程序中的两个活动使用自定义操作和隐式意图进行通信

第一个应用程序(服务器)具有以下清单:

<application android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" android:theme="@style/AppTheme">
    <activity android:name="edu.example.sharing.manager.SecureFileShare"
        android:label="@string/title_activity_secure_file_share" android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="edu.example.sharing.action.STORE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>
    </activity>
</application>
它的表现是正常的。但是,当我尝试在客户端应用程序中发送意图时,我收到一个“未找到活动”异常:

FATAL EXCEPTION: main
android.content.ActivityNotFoundException: No Activity found to handle Intent {act=edu.example.sharing.action.STORE dat=file:///storage/sdcard0/Download/Alarcon12-Rigoberto.pdf }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.app.Activity.startActivityForResult(Activity.java:3312)

是什么导致Android无法识别第二个应用程序中声明的活动?谢谢。

首先,您只能指定要转到的应用程序;您不能指定要转到哪个活动;我已经回答了如何导航到另一个应用程序;之后,你的控件转到另一个应用程序;您必须在那里处理它

仔细查看后,以下是我的发现:

当您使用内置动作类型并附加数据字段时或当您使用没有数据字段的自定义动作类型时,没有数据元素的
意图过滤器
是可以的

但是,当定义自定义操作和包含数据字段时,必须手动为附加的URI设置
mime类型。声称

通常,类型是从数据本身推断出来的。通过设置此属性,可以禁用该计算并强制显式类型

但事实并非如此。当我放入一个以
.txt
结尾的
文件://
URI时,Android给它分配了一个空
mime类型
,因此它不会匹配任何
意图过滤器
,即使是带有
数据
*/*
mime类型
的过滤器。我需要使用
setDataAndType()
手动设置意图的类型


简言之:在对数据使用自定义操作时,必须手动定义意图的
mime类型。

尝试将导出的属性放入清单中的
文件存储
活动。对我来说,有时在使用
setAction()
设置操作时,它也无法工作,但是后来我转而使用
Intent
构造函数来设置操作,例如:
newintent(“edu.example,manager.action.STORE”)尝试更改操作以匹配包id,使edu.example.manager.action.STORE变为edu.example.manager.FileStore.action.STORE我按照@Varun和Dazzy_G的建议修改了代码,但没有解决问题。我已经重新发布了修改过的版本。这不是真的。隐式意图可以映射到活动、广播接收器或服务。我不是试图选择要转到的活动-我是试图发送一个隐式意图,它应该导致Android选择哪些应用程序可以处理它。您链接到的答案指的是按名称打开应用程序。我们是否可以在我们的一个应用程序(如app1)的意向筛选器操作名称中使用自定义名称。从app2中,我们可以像intent I=new intent(“我的意图”)那样称呼它?@FarazAhmad,是的,我们可以。例如:
FATAL EXCEPTION: main
android.content.ActivityNotFoundException: No Activity found to handle Intent {act=edu.example.sharing.action.STORE dat=file:///storage/sdcard0/Download/Alarcon12-Rigoberto.pdf }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.app.Activity.startActivityForResult(Activity.java:3312)