Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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
如何在Xamarin中侦听用户希望打开具有特定扩展名的文件的事件?_Xamarin_Xamarin.forms - Fatal编程技术网

如何在Xamarin中侦听用户希望打开具有特定扩展名的文件的事件?

如何在Xamarin中侦听用户希望打开具有特定扩展名的文件的事件?,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我的应用程序是用Xamarin编程的,我希望允许用户在我的应用程序中打开pdf 目前,在安卓系统中,当用户点击Gmail中带有PDF文件的附件时,会出现一个名为的对话框,使用完成操作,允许用户选择一个应用程序,手机使用该应用程序打开PDF`文件。我如何通过Xamarin在该对话框中列出(理想情况下,这种方式也适用于其他平台)?您必须更新清单,告诉Android您可以处理pdf文件 <intent-filter > <action andr

我的应用程序是用Xamarin编程的,我希望允许用户在我的应用程序中打开
pdf


目前,在安卓系统中,当用户点击Gmail中带有
PDF文件的附件时,会出现一个名为
的对话框,使用
完成操作,允许用户选择一个应用程序,手机使用该应用程序打开
PDF`文件。我如何通过Xamarin在该对话框中列出(理想情况下,这种方式也适用于其他平台)?

您必须更新清单,告诉Android您可以处理pdf文件

        <intent-filter >
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="application/pdf" />
        </intent-filter>

您必须更新清单,告诉Android您可以处理pdf文件

        <intent-filter >
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="application/pdf" />
        </intent-filter>

您可以创建从
活动派生的新类。您必须使用
ActivityAttribute
以及th
intentfilteratAttribute
对该类进行注释,以便系统可以打开PDF。基本上,
IntentFilter
是Daniel所描述的,而是直接在类上进行注释,而不是XML定义的

[Activity(Label = "PdfActivity")]
[IntentFilter(new[] { Intent.ActionView }, 
              Categories = new[] { Intent.CategoryDefault }, 
              DataMimeType = "application/pdf")]
public class PdfActivity : Activity
{
    /// <summary>
    /// Is called when a PDF shall be opened.
    /// </summary>
    /// <param name="savedInstanceState">The saved instance state.</param>
    protected override void OnCreate(Bundle savedInstanceState)
    {
        // do whatever you have to do
    }
}
[活动(Label=“PdfActivity”)]
[IntentFilter(新[]{Intent.ActionView},
Categories=new[]{Intent.CategoryDefault},
DataMimeType=“application/pdf”)]
公开课真实性:活动
{
/// 
///应打开PDF时调用。
/// 
///保存的实例状态。
创建时受保护的覆盖无效(Bundle savedInstanceState)
{
//做你必须做的事
}
}

您可以创建从
活动派生的新类。您必须使用
ActivityAttribute
以及th
intentfilteratAttribute
对该类进行注释,以便系统可以打开PDF。基本上,
IntentFilter
是Daniel所描述的,而是直接在类上进行注释,而不是XML定义的

[Activity(Label = "PdfActivity")]
[IntentFilter(new[] { Intent.ActionView }, 
              Categories = new[] { Intent.CategoryDefault }, 
              DataMimeType = "application/pdf")]
public class PdfActivity : Activity
{
    /// <summary>
    /// Is called when a PDF shall be opened.
    /// </summary>
    /// <param name="savedInstanceState">The saved instance state.</param>
    protected override void OnCreate(Bundle savedInstanceState)
    {
        // do whatever you have to do
    }
}
[活动(Label=“PdfActivity”)]
[IntentFilter(新[]{Intent.ActionView},
Categories=new[]{Intent.CategoryDefault},
DataMimeType=“application/pdf”)]
公开课真实性:活动
{
/// 
///应打开PDF时调用。
/// 
///保存的实例状态。
创建时受保护的覆盖无效(Bundle savedInstanceState)
{
//做你必须做的事
}
}

好了;)类似的问题也在这里;)类似的问题我理解如何在标准Android中以这种方式标记活动,但我不确定它在Xamarin中如何工作,因为Xamarin似乎会自动生成清单中活动的代码。你能写更多关于Xamarin中应该是什么样子的吗?我知道我会如何在标准Android中以这种方式标记活动,但我不确定它在Xamarin中是如何工作的,因为Xamarin似乎会自动生成清单中活动的代码。你能写更多关于Xamarin的内容吗?如果我使用gmail pdf附件启动我的应用程序,我会在onCreate()中以视图的形式获取意向操作吗如果我使用gmail pdf附件启动我的应用程序,我会在onCreate()中以视图的形式获取意向操作吗