我通过观看互联网上的一些教程来学习 Kotlin。我尝试通过转到 Google 并选择“共享图像”来接收我的应用程序中的图像,但我的应用程序没有显示为选项。
我在 Google、YouTube、ChatGPT、StackOverflow 和 Android Developers 上搜索过解决方案,但还没有找到解决方案。我正在使用 API 34。
这是我的清单。据我了解,我只需要添加
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Fundamentals"
tools:targetApi="31">
<activity
android:name=".MainActivity"
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="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:exported="false">
</activity>
</application>
<queries>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="text/plain" />
</intent>
</queries>
</manifest>
你的代码对我来说看起来不错,我认为问题出在其他地方。
当您使用 Google 应用程序并长按图像时,您可以选择共享该图像:
不过,您实际上分享的只是该图像的链接:
如您所见,标题显示“共享链接”,您甚至可以看到该链接。
链接只是简单的纯文本。如果您希望您的应用程序接收此类链接,您需要将意图过滤器的
data
标签调整为:
<data android:mimeType="text/plain" />
我认为您无法使用 Google 应用程序发送实际图像,但您可以尝试其他应用程序,例如相机。使用原始意图过滤器,您的应用程序应该显示为目标。