gpt4 book ai didi

从 youtube 分享链接时 Android 应用程序不可见

转载 作者:搜寻专家 更新时间:2023-11-01 08:19:00 32 4
gpt4 key购买 nike

问题如下:

我阅读了 android 文档,据我在其他主题中发现,来自 YouTube 的共享链接带有标签“text/plain”。我还发现 SO 中发布了不同的问题,但我的应用程序仍然对 YouTube 共享不可见。

我在 list 中使用了以下过滤器

<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent-filter>

在共享列表中看不到我的应用是什么原因?

最佳答案

您将 Intent 过滤器放在 list 中的什么位置?在 native Android 中,它将进入 <activity>。元素在 list 中,但在 Xamarin.Android 中 Activity 不是直接在 list 中声明,而是在 C# 属性中声明。这是因为 Xamarin.Android 创建了在 Activity 名称之前添加哈希的包装器,因此您需要使用 Activity 类上的属性声明 Intent 过滤器,而不是在 list 中,因为您不知道实际的最终编译 Activity 名称将是什么是。更多信息在这里: https://learn.microsoft.com/en-us/xamarin/android/platform/android-manifest

在模板 Xamarin.Android 应用中,您将看到 [Activity(...)]定义标签的属性, Activity 是否是主启动器等。在编译时,这将生成必要的 Android list <activity>元素。您也可以使用 [IntentFilter(...)] 以这种方式添加 Intent 过滤器属性,因此请尝试在要处理 Intent 的 Activity 类上方添加以下内容:

[IntentFilter (new[] { Intent.ActionSend }, Categories = new[] {Intent.CategoryDefault }, DataMimeType = "text/plain")]

在上下文中:

[Activity(Label = "App1", MainLauncher = true, Icon = "@mipmap/icon")]
[IntentFilter (new[] { Intent.ActionSend }, Categories = new[] {Intent.CategoryDefault }, DataMimeType = "text/plain")]
public class MainActivity : Activity
{
...
}

同样,在编译时,上面的代码会生成 <intent-filter> Android list 中的元素。此生成的 list 将在 obj 中项目的文件夹,当您打开应用项目本身中的 AndroidManifest.xml 文件时,您将看不到这些生成的条目。

关于从 youtube 分享链接时 Android 应用程序不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54116572/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com