【问题标题】:XAMARIN-ANDROID Extracting Zip File From My Android AppXAMARIN-ANDROID 从我的 Android 应用程序中提取 Zip 文件
【发布时间】:2017-11-22 12:15:49
【问题描述】:

我需要启用我的应用程序以提取 zip 文件,并且我想在从设备中单击(选择)一个 zip 文件时打开我的应用程序。 在查看 like thisthis 的一些帖子后,我已经创建和 IntentFilter

    [Activity(Label ="Zip")]
    [IntentFilter(new[] { Intent.ActionView },
    Categories = new[] { Intent.CategoryDefault },
                            DataScheme ="file",
                            DataHost ="*",
                            DataPathPattern = "*\\.zip",
                            DataMimeType = "application/zip"
                            DataPathPattern = "*\\.zip",
                            DataMimeType = "application/zip"
    )]

活动代码在这里:

 protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        
        var uri =  Intent.Data.Path;
        Toast.MakeText(this, uri, ToastLength.Long);
       
    }

问题:当我选择 zip 文件时,我的应用程序没有启动。 参考文档:https://developer.android.com/guide/topics/manifest/data-element.html

【问题讨论】:

  • 还有什么问题?
  • 当我选择 zip 文件时,我的应用没有启动。
  • 来自链接的答案 - 我看到您没有添加 <data android:scheme="file" /> 的 Xamarin 模拟
  • 也是<data android:host="*" />
  • 我已经更新了问题,以问题为准。

标签: android xamarin.android intentfilter


【解决方案1】:

我做了很多测试,最后发现像这样修改我的代码后它可以工作:

DataMimeType = "*/*"

并添加一个条件以限制您的应用仅适用于 .zip 文件:

DataPathPattern = ".*\\.zip"

完整代码:

[Activity(Label = "Zip", MainLauncher = true, Icon = "@drawable/icon")]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault },
                        DataScheme = "file",
                        DataHost = "*",
                        DataPathPattern = ".*\\.zip",
                        DataMimeType = "*/*"
)]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多