0

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

Community
  • 1
  • 1
Technacron
  • 548
  • 5
  • 30

1 Answers1

1

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 = "*/*"
)]
Eren Shen
  • 8,468
  • 1
  • 12
  • 37