Asim Khan
Asim Khan

Reputation: 572

XAMARIN-ANDROID Extracting Zip File From My Android App

I need to enable my app to extract the zip file and I want to open my app when a zip file is clicked (selected) from the device. I have Created and IntentFilter after reviewing some posts like this and this

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

And the code for activity goes here :

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

Problem: when I select the zip file my app is not getting launched. Reference Documentation : https://developer.android.com/guide/topics/manifest/data-element.html

Upvotes: 0

Views: 191

Answers (1)

York Shen
York Shen

Reputation: 9084

I did many test and finally find that after modify my code like this it works :

DataMimeType = "*/*"

And add a condition in order to restrict your app only works for .zip file :

DataPathPattern = ".*\\.zip"

Complete code :

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

Upvotes: 1

Related Questions