Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How to get sharing PDF file's path and open that in our Xamarin App ?

$
0
0

There is a problem I couldn't solve for a long time. I want to get a PDF file's path with the share button from another application to my application which I created with xamarin. I have tried somethings and those solved my problem but that wasn't like I wanted. That was; I downloaded the pdf to my phone storage. So there was a lot of pdf on my phone. After that, I can share those pdf with my app and I can see them in there. But that wasn't exactly what I want. Let's say there is an ABC application which has a lot of pdf. I want to open those pdf and share with my Xamarin App directly without storage them. I can explain this with an example: You have a PDF which you want to share with your friends. You open that Pdf and click the Share button. After that, you'll select which application you want to use like Whatsapp, E-Mail, Skype, Discord, etc. So, at last, you can send your pdf directly to another App without store.

My code behind in main activity:

protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            ZXing.Net.Mobile.Forms.Android.Platform.Init();
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());

            Intent intent = new Intent(Application.Context, typeof(MainActivity));



            var action = Intent.Action;
            var type = Intent.Type;

            if (Android.Content.Intent.ActionSend.Equals(action) &&
                (type?.Equals("text/plain") ?? false))
            {
                var path = Intent.GetStringExtra(Android.Content.Intent.ExtraText);
                Console.WriteLine(path);
            }


            if (Android.Content.Intent.ActionSend.Equals(action) && (type?.Equals("application/pdf") ?? false))
            {
                var uri = (Android.Net.Uri)Intent.GetParcelableExtra(Android.Content.Intent.ExtraStream);
                Context context = Android.App.Application.Context;
                var fullPath = GetFilePath(uri);               
                Navigate(fullPath);

            }
        }

What can I do about that? Thanks.


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>