我的Android应用程序可以从其他应用程序接收URL和图像共享。清单中的以下摘录显示了处理这些共享所涉及的两个活动的定义:
<!-- Activity: Share Handler -->
<activity android:name="com.softframeworks.tabdancer.ShareHandlerActivity"
android:label="@string/shared_browser_url"
android:noHistory="true"
android:windowSoftInputMode="stateHidden">
<!-- Intent filter indicates that this activity can handle text -->
<!-- shared using the SEND action. -->
<intent-filter android:label="@string/app_name" android:priority="777">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<!-- Activity: Image Share Handler -->
<activity android:name="com.softframeworks.tabdancer.edit.icon_cache.ImageShareHandlerActivity"
android:label="@string/app_name"
android:noHistory="true"
android:windowSoftInputMode="stateHidden"
android:parentActivityName="com.softframeworks.tabdancer.ManageActivity">
<!-- Intent filter indicates that this activity can handle images -->
<!-- shared using the SEND action. -->
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
我遇到的问题是,当从Google相册分享照片时,我的应用会出现两次。似乎我的两个活动的intent-filter都与Photos应用程序可以共享的内容相匹配。我希望我的应用程序只能在可以从Photo应用程序接收共享的列表中显示一次。理想情况下,共享将作为图像(而不是URL)完成。
我正在运行Marshmallow的Nexus 7上测试它。
提前致谢。
答案 0 :(得分:0)
我能够通过将清单更改为以下内容来解决此问题:
<!-- Activity: Share Handler -->
<activity android:name="com.softframeworks.tabdancer.ShareHandlerActivity"
android:label="@string/shared_browser_url"
android:noHistory="true"
android:windowSoftInputMode="stateHidden">
<!-- Intent filter indicates that this activity can handle text shared -->
<!-- using the SEND action. -->
<!-- Intent filter also indicates that this activity can handle images -->
<!-- shared using the SEND action. However the code for this activity -->
<!-- redirects image shares to the ImageShareHandlerActivity. -->
<intent-filter android:label="@string/app_name" android:priority="777">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<!-- Activity: Image Share Handler -->
<activity android:name="com.softframeworks.tabdancer.edit.icon_cache.ImageShareHandlerActivity"
android:label="@string/app_name"
android:noHistory="true"
android:windowSoftInputMode="stateHidden"
android:parentActivityName="com.softframeworks.tabdancer.ManageActivity">
</activity>
现在,ShareHandlerActivity处理图像和文本共享。但是,在本活动的onCreate()方法中,我测试了意图的类型。如果是image / *,那么我将共享处理委托给ImageShareHandlerActivity。